# Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Else, if givenYear is 2001 or greater (2001-2100), print "21st century". Else, if givenYear is 1901 or greater (1901-2000), print "20th century". Else (1900 or earlier), print "Long ago". Do NOT end with newline.import java.util.Scanner;public class YearChecker {public static void main (String [] args) {Scanner scnr = new Scanner(System.in);int givenYear;givenYear = scnr.nextInt();

Question
Asked Feb 28, 2020
8 views

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

import java.util.Scanner;

public class YearChecker {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int givenYear;

givenYear = scnr.nextInt();

check_circle

## Expert Answer

star
star
star
star
star
1 Rating
Step 1

The below given java program will obey the following rubrics:

• Importing essential header files.
• Declaring main class, YearChecker.
• Declaring main method, in the main method instantiating Scanner class.
• Displaying message to user to enter year.
• Reading input form user.
• Now checking the input against the given cases to display output to user.
• First case is to, check that, if entered year is equal to or greater than 2101, if yes, then displaying message to user "Distant future.
• In second case, checking that if the entered year is equal to or greater than 2001, if yes, then, displaying message to user "21st Century".
• In third case, if entered year is equal to or greater than 1901, if yes, then displaying message to user "20st Century".
• And if none of the case matches (i.e., the entered year is equal to or less than 1900), then displaying message to user "Long ago".
Step 2

Program code:

//importing essential header file

import java.util.Scanner;

//main class

public class YearChecker

{

//main method

public static void main (String [] args)

{

//instantitating scanner class

Scanner scnr = new Scanner(System.in);

//declaring variable

int givenYear;

//displaying message to user to enter year

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

//reading input from user

givenYear = scnr.nextInt();

//if entered year is equal to or greater than 2101

if(givenYear>=2101)

{

//displaying message to user

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

}

//else if entered year is equal to or greater than 2001

else if(givenYear>...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in
© 2020 bartleby. All Rights Reserved.