首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Java,我需要修改我之前编写的AgeGuess程序,如下所示,在下面的实验2练习1中

使用Java,我需要修改我之前编写的AgeGuess程序,如下所示,在下面的实验2练习1中
EN

Stack Overflow用户
提问于 2020-11-09 04:55:23
回答 1查看 99关注 0票数 0
代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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(“恭喜!!”)用户的猜测年龄是正确的“;}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64746073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档