第三章(二次)作业续。。。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第三章(二次)作业续。。。相关的知识,希望对你有一定的参考价值。

 /*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 }

 

技术分享技术分享技术分享


以上是关于第三章(二次)作业续。。。的主要内容,如果未能解决你的问题,请参考以下文章

MATLAB第二次作业(MATLAB基础与应用(第三版))

MATLAB第二次作业(MATLAB基础与应用(第三版))

MATLAB第二次作业(MATLAB基础与应用(第三版))

团队作业7——第二次项目冲刺(Beta版本)-第三篇

软件工程(2018)第二次结对作业

第二次作业