小编Nem*_*emo的帖子

Java String数组不起作用.代码包括在内

public static void main(String[] args) {
    int LENGTH=0;
    int currentSize=0;
    String[] albumArray = new String[LENGTH];

    Scanner sc = new Scanner(System.in);

    System.out.println("How many tracks are in your album?");
    LENGTH=sc.nextInt();
    System.out.println("Thanks.");
    System.out.println("Please enter " + LENGTH + " track names to add to the album: ");

    //Prompts user to enter values until the array is filled. Repeats until filled.
    while (currentSize < LENGTH){
        System.out.print("Enter track name "+(currentSize+1)+":\t");
        albumArray[currentSize] = sc.nextLine();
        currentSize++;
    }

    for (int i =0; i<LENGTH;i++){
        System.out.println(albumArray[i]);
        System.out.println();
    }

}

} …
Run Code Online (Sandbox Code Playgroud)

java arrays

0
推荐指数
1
解决办法
118
查看次数

标签 统计

arrays ×1

java ×1