Ask Question
1 August, 11:55

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".

+5
Answers (1)
  1. 1 August, 12:05
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers