import java.util.Scanner;
public class AgeGuess {
public static void main(String[] args) {
Scanner scan= new Scanner(System.in); // reading from keyboard new scanner object
System.out.print ("Enter the name: ");
String name = scan.nextLine(); // Adding name
System.out.print ("Enter the age: ");
int ageGuess = scan.nextInt(); // Adding Age
System.out.println ("Name is "+ name); // Display name
System.out.println ("Age is "+ ageGuess); //Display age Guess
//***********************************************************************************************
// Lab 2 Exercise 1: Modify the AgeGuess program to do the following:
// Declare a new int variable - initialize age to a random integer between 0 and 100 (inclusive)
// Asks the user for a guess, save the guess in the ageGuess variable
// Display the correct answer发布于 2020-11-09 05:12:15
扫描器扫描=新扫描程序(System.in);System.out.print (“输入名称:");字符串名称= scan.nextLine();//添加名称System.out.println(”用户生成年龄"+名称);int generatedAge =新随机().nextInt(100);System.out.print (“猜测用户年龄:");int ageGuess = scan.nextInt();//添加年龄System.out.println (“名称为"+名称);//显示名称System.out.println (”年龄为"+ ageGuess);//显示年龄猜测System.out.println(“用户生成年龄为:"+ generatedAge);System.out.println(”猜测用户年龄为:"+ ageGuess);if(generatedAge == ageGuess){ System.out.println(“恭喜!!”)用户的猜测年龄是正确的“;}
https://stackoverflow.com/questions/64746073
复制相似问题