12-26作业

switch实现135学习,246复习,周日休息

代码如下:

 1 package com.kk;
 2 
 3 import java.util.Scanner;
 4 
 5 public class Xuexi03 {
 6     public static void main(String[] args) {
 7         int week=0;
 8         Scanner sc=new Scanner(System.in);
 9         
10         do {
11             System.out.println("请输入星期几(1-7):");
12             week=sc.nextInt();
13         }while(week<1||week>7);
14             switch (week) {
15             case 1:
16             case 3:
17             case 5:
18                 System.out.println("今天要学习");
19                 break;
20             case 2:
21             case 4:
22             case 6:
23                 System.out.println("今天要复习");
24                 break;
25             case 7: 
26                 System.out.println("周日休息");
27                 break;
28             }        
29     }
30 }

结果如下:

小游戏:

 1 package com.kk;
 2 
 3 import java.util.Scanner;
 4 
 5 public class Suiji0000 {
 6     public static void main(String[] args) {
 7         Scanner sc=new Scanner(System.in);
 8         int money=1000;
 9         System.out.println("--------欢迎来到BD22大赌场-------------");
10         
11         while(true) {
12             System.out.println("是否开始游戏(y/n)?");
13             String choose=sc.next();
14             if(!"n".equals(choose)) {
15                 int a=(int)(Math.random()*6)+1;
16                 int b=(int)(Math.random()*6)+1;
17                 int c=(int)(Math.random()*6)+1;
18                 //3-9为小,10-18为大
19                 String result=a+b+c>=10?"大":"小";
20                 
21                 System.out.println("请输入下注金额:");
22                 int pay=sc.nextInt();
23                 System.out.println("请压大压小:");
24                 String guess=sc.next();
25                 
26                 System.out.println("买定离手:"+a+","+b+","+c+"-----"+result);
27                 if(guess.equals(result)) {
28                     System.out.println("恭喜你压中");
29                     money+=pay;
30                 }else {
31                     System.out.println("未中奖");
32                     money-=pay;
33                 }
34                 System.out.println("当前余额:"+money);
35             }else {
36                 System.out.println("谢谢");
37                 break;
38             }
39         }
40         System.out.println("游戏结束");
41     }
42 }

效果如下:

猜你喜欢

转载自www.cnblogs.com/Fkkkkk/p/10180647.html