基本上,我是2天前开始编程的,我制作了这个程序来测试直到现在为止我学到的东西,我制作的程序可以完美地工作((要解释我想做什么,我需要解释一下功能),它的作用是基本,它只是询问您的姓名和年龄,然后给出输出。所以我想做的是,当程序要求输入名称时,防止人们在此处输入数字而不是他们的名字,因为当您输入数字而不是字符串时,程序会报错。因此,总而言之,我要让人们只在其中写一个字符串。
我不确定是否会有帮助,但这是代码:
import java.util.Scanner;
public class Gettininput {
public static void main(String[] args) {
System.out.println("Whats Your Name?");
Scanner Name = new Scanner(System.in);
String My_Name = Name.nextLine();
System.out.println("How Old Are You?");
Scanner Age = new Scanner(System.in);
int My_Age = Age.nextInt();
String MyNewAge;
if(My_Age <= 0) {
MyNewAge = ("not born yet :), cool!!");
}
else if (My_Age >= 1 && My_Age <= 12) {
MyNewAge = ("A small kiddo.");
}
else if (My_Age >= 13 && My_Age <= 18) {
MyNewAge = ("A teenager.");
}
else if (My_Age >= 19 && My_Age <= 30) {
MyNewAge = ("In Your Youthhood.");
}
else if (My_Age >= 31 && My_Age <= 40) {
MyNewAge = ("A well Grown Up.");
}
else if (My_Age >=41 && My_Age <= 70) {
MyNewAge = ("A Middle Aged Person.");
}
else {
MyNewAge = ("a Person That is sitting on the Computer with that Age?");
}
System.out.println("So Your Name Is " + My_Name + " And You Are " + MyNewAge);
}
}