到目前为止,我的代码如下所示:
package kittensworld;
import java.util.Scanner;
public class KittensWorld {
public static void main(String[] args){
System.out.println("What is the first kitten's name?");
Scanner scan = new Scanner(System.in);
String kitten1 = scan.nextLine();
System.out.println("What is the second kitten's name?");
String kitten2 = scan.nextLine();
System.out.println("And the third kiten's name?");
String kitten3 = scan.nextLine();
System.out.println("The first kitten's name is " + kitten1);
System.out.println("The second kitten is " + kitten2);
System.out.println("And last but not least, " + kitten3);
}
}
我将如何循环它以便我可以询问 20 只小猫的名字,而无需复制和粘贴 20 次?