设计并实现程序

来源:百度知道 编辑:UC知道 时间:2024/05/05 21:36:50
模拟一台简单的吃角子老虎机,它随机选择0~9之间的三个数,并排打印出来。如果打印出来的数是一样的,或者其中两个数是一样的,则打印一条相应得语句。继续游戏,直到用户选择退出时为止

public class Test {

public static void main(String[] args) throws IOException {
Random r=new Random();
System.out.println("-----------游戏开始啦---------");
int i=0;
while(i!=1)
{
int a=r.nextInt(10);
int b=r.nextInt(10);
int c=r.nextInt(10);
if(a==b && a==c)
{
System.out.println("三个数是相等的");
}
if(a==b || a==c || b==c )
{
System.out.println("有两个数是相等的");
}

if(a!=b && a!=c && b!=c)
{
System.out.println("一个数都不相等");
}

System.out.println("还要继续吗 ?1结束 0继续");

BufferedReader is= new BufferedReader(new InputStreamReader(System.in));
i=Integer.parseInt(is.readLine());

}

System.out.println("程序结束");
}
}