package practiceGO;
import java.util.Scanner;
/*
 * 6、计算机随机产生一个0~9的数,用户进行猜数。值到猜正确为止。
 */
public class Cto {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			System.out.println("请猜数:");
			int perNum = sc.nextInt();
			int sysNum =(int)(Math.random()*10);
			if (sysNum == perNum) {
				System.out.println("恭喜你猜对了!!");
				break;
			}
		}
	}
}

测试结果:

请猜数:
9
请猜数:
9
请猜数:
9
请猜数:
9
请猜数:
9
请猜数:
9
请猜数:
9
请猜数:
9
请猜数:
9
请猜数:
9
请猜数:
9
请猜数:
9
恭喜你猜对了!!