In the past, we used the most to judge the year or date. In fact, the judgment of the zodiac sign is somewhat similar to the judgment of the year.
Here are all the codes:
import java.util.Scanner;public class Zodiac { public static void main(String[] args){ Scanner input=new Scanner(System.in);//Declare the scanner variable System.out.println("Please enter year");//The system prompts to enter try{ //Speak out the exception while(true){ int birthday = input.nextInt()%12; //User input %12 and convert switch(birth){ case 0:System.out.println("Year of the Monkey");break; case 1:System.out.println("Year of Rooster");break; case 2:System.out.println("Year of Dog");break; case 3:System.out.println("Year of Pig");break; case 4:System.out.println("Year of Rat");break; case 5:System.out.println("Year of Ox");break; case 6:System.out.println("Year of Tiger");break; case 7:System.out.println("Year of Rabbit");break; case 8:System.out.println("Year of the Dragon");break; case 9:System.out.println("Year of the Snake");break; case 10:System.out.println("Year of the Horse");break; case 11:System.out.println("Year of the Sheep");break; default :System.out.println("Wrong! Please enter a number greater than 0"); //Default output of this statement that does not meet the above conditions} } } } catch(Exception e){ //Catch exception System.out.println("Please enter correctly"); e.printStackTrace(); //The location and reason of the error in the program when printing exception information is errored} } }You can test it out. If you still don’t understand anything, you can discuss it in the comment area below.