Chinese Zodiac Sign Java Program

Chinese Zodiac Sign Java Program | In this section, we will find the Chinese zodiac sign in Java. Chinese Zodiac Sign is a traditional classification usually based on the lunar calendar assigned to an animal.

This was started in China and many countries like Japan, Bhutan, East Asia, Southeast Asian countries, South Korea, Taiwan, Vietnam, Cambodia, Singapore, Nepal, Thailand use these Zodiac Signs. The Chinese zodiac sign is completely based on the year.

It reduces the given year to 12 as there are 12 animals assigned to each year. The animals assigned are monkey, rooster, dog, pig, rat, ox, tiger, rabbit, dragon, snake, horse, sheep. The monkey starts from index 0 and the sheep ends at index 11. Hence there are 12 animals assigned to each year.

To find out the year assigned to these 12 animals we do year mod 12. Mod operation returns the remainder. Chinese Zodiac Sign is a twelve-year cycle, that is after every 12 years the cycle repeats. These animals say how you represent yourself that is it resembles our characters.

0: Monkey
1: Rooster
2: Dog
3: Pig
4: Rat
5: Ox
6: Tiger
7: Rabbit
8: Dragon
9: Snake
10: Horse
11: Sheep

Chinese Zodiac Sign Java Program

For example:-
let the year be 2022, now
2022 % 12 = 6
Hence the animal will be the tiger.

Example-2:-
Year = 3456
3456 % 2 = 0
Hence the animal will be the monkey.

Example-3:-
Year = 1984
1984 % 12 = 4
The animal is the rat.

Now let us see the implementation of the Chinese Zodiac Sign Java Program. This program uses a switch condition to implement this Chinese Zodiac sign.

Chinese Zodiac Sign Java Program

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {
      Scanner scan = new Scanner(System.in);

      System.out.print("Enter a year: ");
      int year = scan.nextInt();

      switch (year % 12) {
      case 0:
         System.out.println("Monkey");
         break;
      case 1:
         System.out.println("Rooster");
         break;
      case 2:
         System.out.println("Dog");
         break;
      case 3:
         System.out.println("Pig");
         break;
      case 4:
         System.out.println("Rat");
         break;
      case 5:
         System.out.println("Ox");
         break;
      case 6:
         System.out.println("Tiger");
         break;
      case 7:
         System.out.println("Rabbit");
         break;
      case 8:
         System.out.println("Dragon");
         break;
      case 9:
         System.out.println("Snake");
         break;
      case 10:
         System.out.println("Horse");
         break;
      case 11:
         System.out.println("Sheep");
         break;
      }
      scan.close();
   }
}

Output:-

Enter a year: 2025
Snake

Enter a year: 2000
Dragon

Enter a year: 2050
Horse

Also See:- Write a Complete Java Program Called Muchbetter

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *