1.一三五学习,二四六休息,周日休息
1 /** 2 * 一三五学习,二四六休息,周日休息 3 * @author lenovo 4 *12.26 5 */ 6 import java.util.*; 7 public class Switch1 { 8 public static void main(String[]args){ 9 Scanner sc = new Scanner(System.in); 10 System.out.println("请输入今天是周几"); 11 String day = sc.next(); 12 switch(day) { 13 case "一": 14 case "三": 15 case "五": 16 System.out.println("今天学习"); // 一三五的情况 17 break; 18 case "二": 19 case "四": 20 case "六": 21 System.out.println("今天复习");// 二四六的情况 22 break; 23 case "日": 24 System.out.println("今天休息"); // 周日的情况 25 } 26 27 } 28 29 }
计算机票价格
1 /** 2 * 计算机票价格 3 * 12.26 4 */ 5 import java.util.Scanner; 6 public class JiPiaoJia { 7 public static void main(String[] args) { 8 Scanner sc = new Scanner(System.in); 9 System.out.println("请输入您出行的月份"); 10 int yue = sc.nextInt(); 11 System.out.println("请问您选择的头等舱还是经济舱?头等舱输入1,经济舱输入2"); 12 int num =sc.nextInt(); 13 double sum; //sum表示机票价格 14 if(yue<4||yue>10) { //非旺季的情况 15 if(num==1) { // 选头等舱 16 sum = 5000*0.5; 17 }else { // 选经济舱 18 sum = 5000*0.4; 19 } 20 } 21 else { // 旺季的情况 22 if(num==1){ // 选头等舱 23 sum = 5000*0.9; 24 }else { // 选经济舱 25 sum = 5000*0.6; 26 } 27 } 28 System.out.println("您的机票价格为:"+sum); 29 } 30 }
做一个猜大小的游戏:
1 /** 2 * 做一个循环的摇塞子系统,使用while 3 * @author 程学伟 4 *12.27 5 */ 6 import java.util.*; 7 public class YaoSaiZi { 8 public static void main(String[] args) { 9 Scanner sc = new Scanner (System.in); 10 int money = 3000; 11 System.out.println("欢迎来到皇家赌场"); 12 while(true) { 13 System.out.println("是否开始游戏:y/n"); 14 String choose = sc.next(); 15 if(!"n".equals(choose)) { //选择n的情况 16 int a = (int)(Math.random()*6)+1; //随机生成一个1-6的数 17 int b = (int)(Math.random()*6)+1; 18 int c = (int)(Math.random()*6)+1; 19 String result = (a+b+c)>10?"大":"小"; //3-10是小,11-18是大 20 System.out.println("请下注金额"); 21 int pay = sc.nextInt(); 22 System.out.println("买大还是买小?"); 23 String guess =sc.next(); 24 System.out.println("买定离手:"+a+","+b+","+c+"——"+result); 25 if(guess.equals(result)) { // 猜对的情况 26 money +=pay; 27 System.out.println("恭喜你猜对了"); 28 }else { //猜错的情况 29 money -=pay; 30 System.out.println("对不起你猜错了"); 31 } 32 System.out.println("你现在还剩金额:"+money); 33 34 }else { // 选n的情况 35 System.out.println("正在关闭游戏"); 36 break; // 终止循环 37 } 38 } 39 System.out.println("游戏结束"); 40 } 41 }