到目前爲止,我的代碼看起來是這樣的:如何在Java中
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次?
只需使用一個循環。你還在找什麼? – Lion
@Lion Arrays,也許? – Ingo
創建一個'String'的數組:String [] kittens = new String [20]' –