12.31作业
1.骰子游戏
package com.XuanZe; import java.util.Scanner; /* * Game.java * 2018-12-26 * @Boer * 骰子赌博游戏 * */ public class Game { public static void main(String[] args) { //导入一个键盘输入的类 Scanner input = new Scanner(System.in); //定义钱数 int money = 1000; System.out.println("*****欢迎来到澳门赌场*****"); System.out.println("是否开始游戏Y/N?"); String Y_N = input.next(); //判断是否游戏除了输入N,否则视为开始游戏 while(money>=0) { if(!"N".equals(Y_N)) { System.out.print("请压大小:"); //定义yaDaXiao String pay = input.next(); if(pay.equals("大")) { System.out.println("输入有误"); continue; } System.out.print("请下注:"); //定义下注yaQian int paymoney = input.nextInt(); if(paymoney<=100) { System.out.println("输入金额必须大于100!"); continue; } int j = 0; int p; int g; String zuobi; do { if(paymoney>500) j = (int)(Math.random()*6)+1; p = (int)(Math.random()*6)+1; g = (int)(Math.random()*6)+1; zuobi = (j+p+g)>9?"小":"大"; }while(pay.equals(zuobi)); int a = (int)(Math.random()*6)+1; int b = (int)(Math.random()*6)+1; int c = (int)(Math.random()*6)+1; String size = (a+b+c)>9?"大":"小"; //定义结果daoXiao System.out.println("买定离手"+a+","+b+","+c+","+pay); //输出骰子结果 if(pay.equals(zuobi)) { System.out.println("恭喜你压中了"); money += paymoney; }else { System.out.println("很遗憾你没中奖"); money -= paymoney; } System.out.println("当前余额"+money); if(money<100) { System.out.println("请充值"); double num = input.nextDouble(); money +=num; System.out.println("余额"+money); } } else { System.out.println("请退出!"); } } } } //
2.求最大值最小值
package com.xunhuan; /* *Zuidazhi.java *@Boer *12.29 *求最大值最小值 */ import java.util.*; public class Zuidazhi { public static void main(String[] args) { Scanner input = new Scanner(System.in); double num; double max = 0; double min = 0; do{ System.out.print("请输入一个数(输入0结束):"); num = input.nextDouble(); if(max-num<0) { max=num; } if(min-num>0){ min = num; } }while(num!=0); System.out.println("最大值为"+max); System.out.println("最小值为"+min); } }