Java的一个小程序希望好心人修改一下
importjava.util.Scanner;publicclassExerciseSeven{publicstaticvoidmain(Stringargs[]){S...
import java.util.Scanner;
public class ExerciseSeven{
public static void main(String args[]){
String name;
String s="name";
int i=s.length();
Scanner scan = new Scanner (System.in);
System.out.println("Please enter your name");
name=scan.nextLine();
while(i==0){
System.out.println("You forgot to enter your name");
System.out.println("Please try again");
}
while(i!=0){
System.out.println("Hello,"+ name);
break;
}
}
}
像作业那样显示的 现在我不管输入空格也直接到hello了,希望修改一下下啦 展开
public class ExerciseSeven{
public static void main(String args[]){
String name;
String s="name";
int i=s.length();
Scanner scan = new Scanner (System.in);
System.out.println("Please enter your name");
name=scan.nextLine();
while(i==0){
System.out.println("You forgot to enter your name");
System.out.println("Please try again");
}
while(i!=0){
System.out.println("Hello,"+ name);
break;
}
}
}
像作业那样显示的 现在我不管输入空格也直接到hello了,希望修改一下下啦 展开
3个回答
展开全部
import java.util.Scanner;
public class ExerciseSeven{
public static void main(String args[]){
String name;
Scanner scan = new Scanner (System.in);
System.out.print("Please enter your name:");
name=scan.nextLine();
while(name.length() == 0){
System.out.println("You forgot to enter your name!");
System.out.print("Please try again:");
name = scan.nextLine();
}
while(name.length() != 0){
System.out.println("Hello,"+ name);
break;
}
}
}
代码已经修改如上,很简单,相信你能够看得懂。不懂的再追问。我和你一样,都在学习java。加油!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询