It should be more like this because you have to input n
times from the user:
int n = myScan.nextInt();
int[] bar = new int[n];
for (int i=0; i<bar.length; i++) {
int n = myScan.nextInt();
bar[i] = n;
}
I consider using long
instead of int
in this situation.
Incase you want to store each digit in an array, you must use a multidimensional array which pretty much should be as below:
int number = myScan.nextInt();
int[][] bar = new int[number][12];
for (int i=0; i<bar.length; i++) {
for (int j=0; j<bar[i].length; j++) {
int n = myScan.nextInt();
bar[i][j] = n;
}
And you will have a 2D array [x][]
where x
will be the index number from 0-(number-1)
of the particular barcode and [x][0]-[x][11]
will be the barcode digits at the index number x
.
14
solved Valid or invalid barcodes [closed]