
代码如下:
/* ? 多分支练习彩票游戏,随机生成两个一位数的随机数,提示用户输入猜测的数字 ? 如果完全匹配奖金10000,只匹配数字没有匹配顺序奖金3000,只匹配一个数字奖金1000 ? 例:若生成的随机数为18,如果用户输入18奖金10000;如果用户输入81奖金3000;如果用户输入16奖金1000 */ import java.util.Scanner; class Demo13 { public static void main(String[] args)? { //随机生成两个一位数的数字 int a=(int)(Math.random()*10); int b=(int)(Math.random()*10); System.out.println(a+","+b); //提示用户输入猜测数字 Scanner sc=new Scanner(System.in); System.out.println("请输入你猜测的数字:"); int x=sc.nextInt(); int y=sc.nextInt(); //判断 if(a==x&&b==y) System.out.println("中奖10000元"); else if(a==y&&b==x) System.out.println("中奖3000元"); else if(a==x||a==y||b==x||b==y) System.out.println("中奖1000元"); else System.out.println("未中奖,欢迎继续来玩"); } }
(编辑:北几岛)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|