Write a java program to find out the Chinese Zodiac sign for a given year using
ID: 3675846 • Letter: W
Question
Write a java program to find out the Chinese Zodiac sign for a given year using an array of strings to store the animal names. The Chinese Zodiac is based on a twelve-year cycle, with each year represented by a different animal: monkey, rooster, dog, pig, rat, ox, tiger, rabbit, dragon, snake, horse, or sheep—in this cycle. Note that year % 12 determines the Zodiac sign.
year % 12 =
0: monkey
1: rooster
2: dog
3: pig
4: rat
5: ox
6: tiger
7: rabbit
8: dragon
9: snake
10: horse
11: sheep
For example: 1900 is the year of the rat because 1900 % 12 = 4
Starting code:
// John Smith, 123456789
import java.util.Scanner;
public class ChineseZodiac {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a year: ");
int year = input.nextInt();
// To be finished by you
Explanation / Answer
import java.util.*;
public class ChineseZodiac
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a year: ");
int year = input.nextInt();
int n=year%12;
String[] zodiac = { "monkey","rooster","dog","pig","rat","ox","tiger","rabbit","dragon", "snake", "horse", "sheep"};
for ( int i=0; i<12; i++ )
{
if( i = n )
System.out.println(" Zodiac Sign is"+ zodiac[i]);
}
}
}
Output:
Enter a year: 1900
Zodiac Sign is rat
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.