一,课后第三题机票

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 = ;//设定机票
double pay = ;//赋值
if(month>=&&month<=) {
if(air==) {
pay = money*0.9;
System.out.println("您的机票价格为:"+pay);
}else {
pay = money*0.6;
System.out.println("您的机票价格为:"+pay);
}
}else {
if(air==) {
pay = money*0.5;
System.out.println("您的机票价格为:"+pay);
}else {
pay = money*0.4;
System.out.println("您的机票价格为:"+pay);
}
}
}
}

课后作业机票,赌骰子游戏,switch的使用实例-LMLPHP

二,赌骰子游戏

import java.util.MissingFormatArgumentException;
import java.util.Scanner; public class Game {
public static void main(String[] args) {
System.out.println("欢迎来到澳门大赌场");
int money = ;
System.out.println("是否开始Game(是/否)?");
Scanner sc = new Scanner(System.in);
String choose = sc.next();
if(!"否".equals(choose)) {
int a = (int)(Math.random()*);
String result =(a)>=?"大":"小"; 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的使用实例-LMLPHP

三,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 :
case :
case :
System.out.println("学习");
break;
case :
case :
case :
System.out.println("复习");
break;
default:
System.out.println("休息");
}
}
}

课后作业机票,赌骰子游戏,switch的使用实例-LMLPHP

05-08 07:50