//猜字游戏。要求猜一个介于1到10之间的数字。然后将猜测的值与实际值进行比较,
//并给出提示,以便能更接近实际值,直到猜中为止。
package com.imooc.flow1;
import java.util.Scanner;
public class GuessDemo {
public static void main(String[] args) {
//猜字游戏。要求猜一个介于1到10之间的数字。然后将猜测的值与实际值进行比较,
//并给出提示,以便能更接近实际值,直到猜中为止。
int number=6;
int guess;
System.out.println("==猜一个介于1-10之间的数字==");
do{
Scanner sc=new Scanner(System.in);
System.out.println("请输入您猜测的数字:");
guess=sc.nextInt();
if(guess-number>0){
System.out.println("您输入的数字偏大");
}
if(guess-number<0){
System.out.println("您输入的数字偏小");
}
}while(guess-number!=0);
System.out.println("您猜对了!");
}
}