Thursday 25 August 2016

Chapter 7 Exercise 33, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.



*7.33 (Culture: Chinese Zodiac) Simplify Listing 3.9 using an array of strings to store the animal names.



import java.util.Scanner;
 
 
public class ProgrammingEx7_33 {
 
 public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
 
  System.out.print("Enter a year: ");
  int year = input.nextInt();
  int index = (year % 12);
  String[] zodiac = { "monkey", "rooster", "dog", "pig", "rat", "ox",
    "tiger", "rabbit", "dragon", "snake", "horse", "sheep", };
  System.out.println(zodiac[index]);
 }
 
}

No comments :

Post a Comment