这个题目最核心的关键点就是
int number = (int)(Math.random()*100+1);
package L; import java.util.Scanner; public class caishu { public static void main(String[] args) { // TODO 自动生成的方法存根 Scanner in = new Scanner(System.in); int number = (int)(Math.random()*100+1); int a; int count = 0 ; do { a=in.nextInt(); count = count+1; if(a>number) { System.out.println("偏大"); } else if (a<number) { System.out.println("偏小"); } }while(a !=number); System.out.println("恭喜你猜对了,你猜了"+count+"次"); } }