刚写的
import?java.util.Scanner;public?class?Main{
public?static?void?main(String[]?args)?{
Scanner?sc?=?new?Scanner(System.in);
double?dNum?=?100?*?Math.random();
int?iNum?=?(int)?dNum,?inNum,?count?=?0;
while(true)?{
inNum?=?sc.nextInt();
if(inNum?==?iNum)?{
System.out.print("猜对了.n");
break;
}?else?if(++count?==?10)?{
System.out.print("猜测次数已达10次,猜数失败.n");
break;
}?else?if(inNum?<?iNum)?{
System.out.print("输入的值小,请输入更大的数.n");
}?else?if(inNum?>?iNum)?{
System.out.print("输入的值大,请输入更小的数.");
}
}
sc.close();
}
}
import java.util.Scanner;
public class Guess{
public static void main(String[] args){
int i,r,count=0;
boolean flag=false;
Scanner input=new Scanner(System.in);
do{
System.out.print("我猜这个数是:");
i=input.nextInt();
r=(int)(Math.random() * 100);
if(i==r){
System.out.println("你的得分是:"+(100-10*count));
flag=true;
break;
}
else{
count++;
System.out.println("本次产生的随机数是:"+r);
}
}while(count<10);
if(!flag){
System.out.println("超过规定的次数,不计入成绩.");
}
}
}
免责声明:本平台仅供信息发布交流之途,请谨慎判断信息真伪。如遇虚假诈骗信息,请立即举报
举报