其实感觉,就掌握这个就好了.
import java.util.Scanner;
public class Demo6 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入您猜的数字:");
int or = (int) (Math.random() * 100 + 1);
while (true) {
int num = sc.nextInt();
if (num > or) {
System.out.println("大了");
} else if (num < or) {
System.out.println("小了");
} else {
System.out.println("终于对了");
break;
}
}
}
}
|