import java.util.Scanner;
public class App {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int[][] numberPair = new int [2][x];
for(int i=0; i<x; i++){
for(int k=0; k<2; k++){
numberPair[k][i] = sc.nextInt();
}
}
int[] solution = new int[x];
for(int i=0; i<x; i++){
if(numberPair[0][i]<numberPair[1][i]){
//a minimum
solution[i] = numberPair[0][i];
}
else {
//b min
solution[i] = numberPair[1][i];
}
for(i=0; i<x; i++)
System.out.printf(solution[i] + " ");
}
}
}
Java newb here! This is a basic exercise for choosing the small number between two numbers in a given list and printing them out. It always gives the correct answer for the first one but 0 for the following. I couldn't figure out why, any help or tip will be appreciated thanks :)
the small number between two numbers in a given list... can you give us an example of what you mean exactly?