mardi 7 avril 2015

Java String array not working. Code included.

Vote count:


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

Scanner sc = new Scanner(;

System.out.println("How many tracks are in your album?");
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();

for (int i =0; i<LENGTH;i++){



Okay, so basically this program allows the user to create an album. The user sets the number of tracks (LENGTH) in the array, and then assigns a String value to each index in the array. I'm getting an error under line 18 "albumArray[currentSize] = sc.nextLine();".

Does anyone know what I'm doing wrong here? thanks in advance.

asked 1 min ago

Java String array not working. Code included.

Aucun commentaire:

Enregistrer un commentaire