代码奉上:
import java.util.Scanner;
public class Example{
public static void main(String[] args){
System.out.println("欢迎来到猜数字小游戏!");
System.out.println("请输入一个整数:");
int num;
int guess;
Scanner scanner = new Scanner(System.in);
num = scanner.nextInt();
System.out.println("请猜猜这个数字是多少:");
guess = scanner.nextInt();
if(guess == num){
System.out.println("恭喜你,猜对了,答案是: " num);
} else if(guess > num){
System.out.println("您猜的数字大了,正确答案是:" num);
} else {
System.out.println("您猜的数字小了,正确答案是:" num);
}
System.out.println("游戏结束!");
}
}
没有回复内容