ok so ive to hand this question in by the end of today 19:00
Here's the Q.Declare an array of 50 student numbers and fill it with integers between 1 and 1000.
Output all elements to the screen. Check if there are duplicates and if so output the index at which these duplicates occur. e.g. Student[21] = 444 Student[33] = 444
I know my problem is in the 3rd nested loop with the intiger i,
class WS5bQ2 { public static void main(String args[]) { int grade[][] = new int[1][50]; for(int row=0; row<grade.length; row++)//loop to assingn values to the array { for(int col=0; col<50; col++)//controls the col { grade[row][col] = (int)(Math.random()*10000000%1000+1); } } for(int row=0; row<grade.length; row++)//output array to screen { for(int col=0; col<50; col++) { System.out.print(grade[row][col]+" "); } } System.out.println(""); for(int row =0; row<grade.length; row++)//nested loop to check for matching grades { for(int col = 1; col <grade.length; col++) { int i = 0; if(grade[row][i] == grade[row][col]) { System.out.println("Stundent "+i+ "= "+grade[row][i]+" Stundent "+col+"= "+grade[row][col]); } i++; }//close second loop }//close 1st loop }//close main }//close class
ive laso tried the 3rd nested loop this way
for(int i =0; i<=49; i++)//nested loop to check for matching grades { for(int col = 1; col <grade.length; col++) { if(grade[0][i] == grade[0][col]) { System.out.println("Stundent "+i+ "= "+grade[0][i]+" Stundent "+col+"= "+grade[0][col]); } }//close second loop }//close 1st loop