编写一个java程序,询问用户他/她的姓名,年龄和薪水(双倍)。遵循输入/输出格式。
以下对话应在屏幕上显示为输出,您将在其中输入姓名,年龄和工资的值。
假设您的输入是:
约翰
22
500 预期产出:
您好。你叫什么名字? 你好,约翰!你几岁? 所以你22岁?那根本不老! 你为约翰做了多少?
500.0!我希望每小时而不是每年! LOL!
我试着像这样解决
import java.util.Scanner;
class Enquiry
{
public static void main(String args[])
{
Scanner scanner=new Scanner(System.in);
do{
System.out.println("Hello. What is your name?");
string name1 = scanner.nextString();
}
while(name1 != null)
{
System.out.println("Hi" +name1 "! How old are you?");
int age = scanner.nextInt();
}
while(age != null)
{
System.out.println("So you're" +age "eh? That's not old at all!"); System.out.println("How much do you make John?");
double salary = scanner.nextDouble();
}
while(salary != null)
{
System.out.println(+salary"! I hope that's per hour and not per year! LOL!");
}
}
}
任何人都可以帮助我解决这个问题以及我所犯的错误 谢谢,非常感谢您的帮助
答案 0 :(得分:0)
有很多错误,比如
1。)不需要do - while loops
。
2.。)字符串与+
运算符连接,在system.out.println()
语句中缺失。
3。)string name1
,S
应为大写,String
是一个java关键字,指的是数据类型。
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
System.out.println("Hello. What is your name?");
String name1 = scanner.nextLine();
System.out.println("Hi" + name1 + "! How old are you?");
int age = scanner.nextInt();
System.out.println("So you're" + age + "eh? That's not old at all!");
System.out.println("How much do you make John?");
double salary = scanner.nextDouble();
System.out.println(+salary + "! I hope that's per hour and not per year! LOL!");
}
<强>输出强>
Hello. What is your name?
John
HiJohn! How old are you?
22
So you're22eh? That's not old at all!
How much do you make John?
500
500.0! I hope that's per hour and not per year! LOL!