200k views
1 vote
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".

User YuvShap
by
7.8k points

1 Answer

1 vote

Answer:

import java.util.Scanner;

public class num9 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

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

int givenYear =in.nextInt();

if(givenYear>=2101){

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

}

else if(givenYear>=2001){

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

}

}

}

Step-by-step explanation:

  • Using Java programming Language
  • Import Scanner class to receive user input of the variable givenYear
  • Use if statement to check the first condition if(givenYear>=2101)
  • Use else if statement to check the second condition if(givenYear>=2001)
  • print Distant future and 21st century respectively
User Anmol Gupta
by
8.4k points