猜数字游戏
import java.util.Random;
import java.util.Scanner;
public class 猜数字游戏 {
public static void main(String[] args) {
Random r=new Random();
int number=r.nextInt(100)+1;
while(true){
System.out.println("请输入你猜的数字");
Scanner sc=new Scanner (System.in);
int guessnumber=sc.nextInt();
if(guessnumber>number){
System.out.println("你猜的数字大了");
}
else if(guessnumber<number){
System.out.println("你猜的数字小了");
}
else{
System.out.println("恭喜你猜对了");
break;
}
}
}}
坚持每天写日记,加油!
最后
以上就是友好咖啡豆最近收集整理的关于java小白的第一个程序的全部内容,更多相关java小白内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复