Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Barcode problem

962826Jan 24 2013 — edited Jan 25 2013
Hi - I have to enter a string of numbers (at least 5) that will represent a barcode and check for correctness using an algorithm. I am having problems just getting started.

<code>
public static void main(String[] args) {
int x = 0;

// Enter a a barcode number, must be at least 5 digits
Scanner input = new Scanner(System.in);
System.out.println("Please enter a number that contains at least 5 digits: ");

//Create an array
double[] myBarcode = new double[x];

//Store the numbers in array
for (int index = 0; index < myBarcode.length; index++){
myBarcode[index] = input.nextDouble();
}


}
}
<code>

How do I enter an unspecified amount of numbers as a string and then store them in an array without knowing what the amount of numbers is even going to be? Additionally, how would include something in the program to verify that each character is a numeric digit?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 22 2013
Added on Jan 24 2013
6 comments
1,134 views