12-28博彩
代码如下:
1 package com.kkkk; 2 3 import java.util.Scanner; 4 5 public class Lianxi002 { 6 public static void main(String[] args) { 7 Scanner sc = new Scanner(System.in); 8 9 double money = 0;//金钱 10 int sum = 0;//总点数 11 String balance = "";//是否充值 12 String botton = "";//重新下注 13 String guess = "";//压大或小 14 String result = "";//开奖大小 15 int pay = 0;//下注金额 16 17 System.out.println("-------欢迎使用kkk赌博系统------"); 18 System.out.println("当钱余额:" + money); 19 System.out.println("是否充值(y/n)?"); 20 balance = sc.next(); 21 do { 22 //询问是否充值 23 if ("y".equals(balance)) { 24 System.out.println("请输入充值金额:"); 25 double recarge = sc.nextDouble(); 26 money = recarge; 27 System.out.println("充值成功,当前余额位:" + money); 28 System.out.println("---------------------------"); 29 } else { 30 balance = "n"; 31 } 32 //询问是否下注 33 while ("y".equals(balance)) { 34 System.out.println("是否开始游戏(y/n)"); 35 int a = (int) (Math.random() * 6 + 1); 36 int b = (int) (Math.random() * 6 + 1); 37 int c = (int) (Math.random() * 6 + 1); 38 String go = sc.next(); 39 //询问是否下注金额 40 if ("y".equals(go)) { 41 result = (a + b + c) >= 10 ? "大" : "小"; 42 System.out.println("请输入下注金额:"); 43 pay = sc.nextInt(); 44 System.out.println("请压大或者压小:"); 45 guess = sc.next(); 46 //判断余额是否足够下注? 47 if (money - pay >= 0) { 48 money =money-pay; 49 System.out.println("下注成功,当前余额为" + money); 50 System.out.println("当前点数为:" + a + " , " + b + " , " + c); 51 sum = a + b + c; 52 System.out.println("总点数是" + sum + ",结果为:" + result); 53 botton="y"; 54 } else { 55 System.out.println("当前余额不足,剩余"+money+",下注失败,请重新下注"); 56 go = "y"; 57 } 58 while ("y".equals(botton)) { 59 //判断是否中奖 60 if (guess.equals(result)) { 61 System.out.println("恭喜你压中了!!"); 62 money = money + pay * 2; 63 System.out.println("当前余额为" + money); 64 } else { 65 System.out.println("很遗憾,没有中奖"); 66 System.out.println("当前余额为" + money); 67 } 68 botton="n"; 69 go = "y"; 70 } 71 } else { 72 balance = "n"; 73 } 74 } 75 System.out.println("谢谢使用"); 76 } while ("y".equals(balance)); 77 } 78 }