Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In JAVA Write an if-else statement with multiple branches. If givenYear is 2100

ID: 3888260 • Letter: I

Question

In JAVA

Write an if-else statement with multiple branches. If givenYear is 2100 or greater, print "Distant future" (without quotes). Else, if givenYear is 2000 or greater (2000-2099), print "21st century". Else, if givenYear is 1900 or greater (1900-1999), print "20th century". Else (1899 or earlier), print "Long ago". Do NOT end with newline.

With the following code:

import java.util.Scanner;

public class YearChecker {
   public static void main (String [] args) {
      int givenYear = 0;

      givenYear = 1776;

      /* Your solution goes here */

      return;
   }
}

Explanation / Answer

import java.util.Scanner;

class YearChecker {
public static void main (String [] args) {
int givenYear = 0;
givenYear = 1776;
  
/* Your solution goes here */
  
Scanner input = new Scanner(System.in);
  
System.out.println("Enter the year : "); //input the year
givenYear = input.nextInt();
  
if(givenYear >= 2100) //year is greater than or equal to 2100
System.out.println("Distant Future");
else if(givenYear >= 2000 && givenYear <= 2099) //year is between 2000 and 2099
System.out.println(" 21st Centuary");
else if(givenYear >= 1900 && givenYear <= 1999) //year is between 1900 and 1999
System.out.println(" 20th Centuary");
else if(givenYear <=1899) // year is less than or equal to 1899
System.out.println(" Long Ago");
  
return;
}
}

Output:

Enter the year : 1776

Long Ago

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote