I'm a newbie to Java and here I am trying to minimize the amount of code I've written. I want to add elements to 2 arrays of the same size using only one for loop. I tried many ways but it ended up adding the same elements to both arrays. How can I loop twice and add different elements?
This's how I did it using two for loops...
public static void main (String[] args) throws IOException {
BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
int size = Integer.parseInt(reader.readLine());
int[] arr1 = new int[size];
int[] arr2 = new int[size];
String[] elem1 = reader.readLine().split("\\s+");
for(int i = 0; i < size; i++)
{
arr1[i] = Integer.parseInt(elem1[i]);
}
String[] elem2 = reader.readLine().split("\\s+");
for(int j = 0; j < size; j++)
{
arr2[j] = Integer.parseInt(elem2[j]);
}
System.out.println(LargestPair( arr1, arr2, size));
}