I'm working on a project to reverse arrays and print the largest of all elements. For simplicity I have reduced this problem just to printing two arrays the same way they have been written down. The maximum length of an array is 10. The arrays are given by the user, the integers are seperated by spaces and the two arrays are seperated with an enter.
MY CODE
package testing;
import java.io.PrintStream;
import java.util.Locale;
import java.util.Scanner;
public class Testing {
PrintStream out;
Testing() {
out = new PrintStream(System.out);
}
int[] fillArray(Scanner in) {
int[] k = new int[10];
int position = 0;
in.useDelimiter(" ");
while(in.hasNextInt()) {
k[position] = in.nextInt();
position++;
}
return k;
}
void printArray(int[] array) {
for(int i = 0; i<10; i++) {
System.out.printf("%d ", array[i]);
}
System.out.println();
}
void start() {
Scanner in = new Scanner(System.in);
int[] a = new int[10];
int[] b = new int[10];
a = fillArray(in);
b = fillArray(in);
printArray(a);
printArray(b);
}
public static void main(String[] args) {
Locale.setDefault(Locale.US);
new Testing().start();
}
}
When I run this code I get this, why won't the second array just print what I want?
(This is probably a scanner thing which I'm not able to solve).