Ask Question
11 July, 21:58

Write an if-else statement with multiple branches. If year is 2101 or later, print "Distant future" (without quotes). Otherwise, if year is 2001 or greater, print "21st century". Otherwise, if year is 1901 or greater, print "20th century". Else (1900 or earlier), print "Long ago".

+1
Answers (1)
  1. 11 July, 22:17
    0
    import java. util. Scanner;

    public class Car {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter a year");

    int year = in. nextInt ();

    if (year<=1900) {

    System. out. println ("Long ago");

    }

    else if (year >=1901&& year < 2001) {

    System. out. println ("20th Century");

    }

    else if (year> 2001 && year<2101) {

    System. out. println ("21st Century");

    }

    else{

    System. out. println ("Distant Future");

    }

    }

    }

    Explanation:

    This is implemented in Java programming First the Scanner class is used to receive user input for year and stored in the variable year Using if ... else statements, we start from year less that 1900 (Long ago), else if year is equal to or greater than 1901 but less that 2001 (20th century); else if year is between 2001 and 2101 (21st Century) Else (Distant future)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write an if-else statement with multiple branches. If year is 2101 or later, print "Distant future" (without quotes). Otherwise, if year is ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers