Java作业五(2017-10-15)

时间:2022-12-17 10:16:43
 /*3-6.程序员;龚猛*/
 1
package zhenshu; 2 import java.util.Scanner; 3 public class text { 4 5 public static void main(String[] args) { 6 Scanner input = new Scanner(System.in); 7 8 System.out.print("Enter an integer:"); 9 int number = input.nextInt(); 10 11 if (number % 2 == 0 && number % 3 == 0) 12 System.out.println(number + "is divisible by 2 and 3."); 13 14 if (number % 2 == 0 || number % 3 == 0) 15 System.out.println(number + "is divisible by 2 and 3."); 16 17 if (number % 2 == 0 ^ number % 3 == 0) 18 System.out.println(number + "is divisible by 2 and 3. but not both."); 19 20 } 21 22 }
 1 /*3-7*/
 2 package zhenshu;
 3 import java.util.Scanner;
 4 public class Year {
 5 
 6     public static void main(String[] args) {
 7         Scanner input = new Scanner(System.in);
 8         System.out.print("Enter a year:");
 9         int year = input.nextInt();
10         
11         boolean isLeapYear =
12                 (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
13         
14         System.out.println(year + "is a leap year?" + isLeapYear);
15     }
16 
17 }

 

 1 /*3-8*/
 2 package zhenshu;
 3 import java.util.Scanner;
 4 public class lottery {
 5 
 6     public static void main(String[] args) {
 7         int lottery = (int)(Math.random() * 100);
 8         
 9         Scanner input = new Scanner(System.in);
10         System.out.print("Enter your lottery pick (two digits):");
11         int guess = input.nextInt();
12         
13         int lotteryDigit1 = lottery / 10;
14         int lotteryDigit2 = lottery % 10;
15         
16         int guessDigit1 = guess / 10;
17         int guessDigit2 = guess % 10;
18         
19         System.out.println("The lottery number is" + lottery);
20         
21         if(guess == lottery)
22             System.out.println("Exact match: you win $10,000");
23         
24         else  if(guessDigit2 == lotteryDigit1 && guessDigit2 == lotteryDigit2 )
25             System.out.println("Match all digits: you win $3,000");
26         else  if(guessDigit1 == lotteryDigit1 || guessDigit1 == lotteryDigit2
27                 ||guessDigit2 == lotteryDigit1 || guessDigit2 == lotteryDigit2)
28             System.out.println("Match all digits: you win $1,000");
29         else
30             System.out.println("Sorry,no match");
31         
32         
33 
34     }
35 
36 }

 

 1 /*3-9*/
 2 package zhenshu;
 3 
 4 import java.util.Scanner;
 5 
 6 public class ChinaYear {
 7 
 8     public static void main(String[] args) {
 9     Scanner input = new Scanner(System.in);
10         
11         System.out.print("Enter a year:");
12         int year = input.nextInt();
13         
14         switch (year % 12){
15         case 0: System.out.println("monkey"); break;
16         case 1: System.out.println("rooster"); break;
17         case 2: System.out.println("dog"); break;
18         case 3: System.out.println("pig"); break;
19         case 4: System.out.println("rat"); break;
20         case 5: System.out.println("ox"); break;
21         case 6: System.out.println("tiger"); break;
22         case 7: System.out.println("rabbit"); break;
23         case 8: System.out.println("dragon"); break;
24         case 9: System.out.println("snake"); break;
25         case 10: System.out.println("horse"); break;
26         case 11: System.out.println("sheep"); break;
27         }
28     }
29 
30 }

 

Java作业五(2017-10-15)Java作业五(2017-10-15)Java作业五(2017-10-15)Java作业五(2017-10-15)