Java 如何以某种方式循环我的主要方法?
例如,程序会要求用户输入,然后它会产生一些输出,然后就完成了,但是如果用户想通过main方法,我怎么能让它再次循环呢 这是我的密码:Java 如何以某种方式循环我的主要方法?,java,loops,main,Java,Loops,Main,例如,程序会要求用户输入,然后它会产生一些输出,然后就完成了,但是如果用户想通过main方法,我怎么能让它再次循环呢 这是我的密码: public static void main(String[] args) { Scanner sc = new Scanner(System. in ); System.out.print("Please enter the first name of the person you would love to know about : ");
public static void main(String[] args) {
Scanner sc = new Scanner(System. in );
System.out.print("Please enter the first name of the person you would love to know about : ");
String hisName = sc.next();
printSomeInfoAbout(hisName);
}
如果用户决定再次运行,我将如何使其再次运行?创建一个获取输入的方法,如果用户选择输入另一个名称,则调用该方法创建一个获取输入的方法,如果用户选择输入另一个名称,则调用该方法一个简单的循环,该循环将检查用户将空字符串作为输入的内容它将退出的名字
String x=null;
Scanner sc = new Scanner(System. in );
String hisName=null;
do{
System.out.print("Please enter the first name of the person you would love to know about : ");
hisName = sc.next();
printSomeInfoAbout(hisName);
System.out.print("y/n");
x=sc.next();
}while(x.equals("y"));
public static void main(String[] args) {
Scanner sc = new Scanner(System. in );
do {
System.out.print("Please enter the first name of the person you would love to know about : ");
String hisName = sc.next();
if (hisName.equals("")) {
printSomeInfoAbout(hisName);
}
} while (!hisName.equals(""));
}
一个简单的循环,它将检查用户将空字符串作为它将退出的名字的任何内容
public static void main(String[] args) {
Scanner sc = new Scanner(System. in );
do {
System.out.print("Please enter the first name of the person you would love to know about : ");
String hisName = sc.next();
if (hisName.equals("")) {
printSomeInfoAbout(hisName);
}
} while (!hisName.equals(""));
}
请查找下面的代码段,它可能会对您有所帮助 公共静态void main(字符串[]args){
请查找下面的代码段,它可能会对您有所帮助 公共静态void main(字符串[]args){
你可以考虑在Oracle网站上做一个完整的(免费的)教程。今天和接下来几个月将帮助你浏览下面的基本知识——“入门”ETCU,你可以考虑做一个完整的(免费的)。oracle网站上的编程教程。将在今天和接下来的几个月内帮助您滚动到下面介绍基本知识的轨迹-“入门”etci猜测应该是如果(var.equals(“Y”):)@Stunner-yup..更改了它。谢谢!工作:)而且我不知道是否要重复主要方法,我必须添加一个(null)。我想应该是(var.equals(“Y”):)@Stunner-yup..更改了它。谢谢!works:)而且我不知道是否要重复主方法,我必须添加一个(null)。
public static void main(String[] args) {
Scanner sc = new Scanner(System. in );
do {
System.out.print("Please enter the first name of the person you would love to know about : ");
String hisName = sc.next();
if (hisName.equals("")) {
printSomeInfoAbout(hisName);
}
} while (!hisName.equals(""));
}
String name;
Scanner scn = new Scanner(System.in);
boolean flag = false;
do {
System.out.println("Please enter the first name of the person you would love to know about : ");
name = scn.next();
System.out.println("Your friend " +name+ " is a great guy..!");
System.out.println();
System.out.println("Enter 1 to continue giving other" +
" names or Enter 2. to quit");
System.out.println();
int choice = scn.nextInt();
if( choice == 1 ) {
flag = true;
} else {
System.out.println("ThankU.. Bye");
flag = false;
}
} while(flag);
}