一,课后第三题机票
package com.bd22; import java.util.Scanner; public class AirTicket { public static void main(String[] args) { System.out.println("请输入您出行的月份"); Scanner sc = new Scanner(System.in); int month = sc.nextInt();//输入月份 System.out.println("请问您选择头等舱还是经济舱?头等舱输入1,经济舱输入2"); int air = sc.nextInt();//输入仓位 double money = 5000;//设定机票 double pay = 0;//赋值 if(month>=4&&month<=10) { if(air==1) { pay = money*0.9; System.out.println("您的机票价格为:"+pay); }else { pay = money*0.6; System.out.println("您的机票价格为:"+pay); } }else { if(air==1) { pay = money*0.5; System.out.println("您的机票价格为:"+pay); }else { pay = money*0.4; System.out.println("您的机票价格为:"+pay); } } } }
二,赌骰子游戏
import java.util.MissingFormatArgumentException; import java.util.Scanner; public class Game { public static void main(String[] args) { System.out.println("欢迎来到澳门大赌场"); int money = 100; System.out.println("是否开始Game(是/否)?"); Scanner sc = new Scanner(System.in); String choose = sc.next(); if(!"否".equals(choose)) { int a = (int)(Math.random()*6); String result =(a)>=3?"大":"小"; System.out.println("请下注"); int pay = sc.nextInt(); System.out.println("请压大或者压小:"); String guess = sc.next(); System.out.println("买定离手"+a); if(guess.equals(result)) { System.out.println("恭喜你压中了"); money += pay; System.out.println("您获得"+money+"金钱"); }else { System.out.println("对不起,您没有压中"); money -= pay; System.out.println("您的余额为:"+money); } }else { System.out.println("你走吧,穷逼"); } } }
三,switch实现135学习,246复习,周日休息
package com.bd22; import java.util.Scanner; public class Swish { public static void main(String[] args) { //判断135学习,246复习,7休息 Scanner sc = new Scanner(System.in); System.out.println("请问查询星期?"); int week = sc.nextInt(); switch (week) { case 1: case 3: case 5: System.out.println("学习"); break; case 2: case 4: case 6: System.out.println("复习"); break; default: System.out.println("休息"); } } }