Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)

 JackDaniels 1Jun2009 00:52

Can someone help me to make a program in java:
1. Generate 2 rows of 50 random numbers (int) from 0 to 99.
2. Search the numbers that appear in the first row, but not in the second, and numbers that appear in the second row but not in the first. Print the result.
By now I have this:
Code:

```import java.util.Random; public class RandomNum {         int i, j;         int AllNumbers[][] = new int [2][50];         AllNumbers[50] = new int[50];         AllNumbers[50] = new int[50];         for (i=0; i<=50; i++){                 for (j=0; j<=50; j++){                         AllNumbers[i][j] = RandomNum.nextInt (100);                         System.out.println(AllNumbers[i][j] + " ");                         }                 }         }```
}

I doubt if you have any java programming experience at all ! :mad:
Look what you have written :
Code: java

`int AllNumbers[][] = new int [2][50];AllNumbers[50] = new int[50];AllNumbers[50] = new int[50];`

You have already allocated memory for AllNumbers in the first statement itself. So no need for the 2nd and 3rd statements. Further, the second and third statements are duplicates and they try to access AllNumbers[50] where as AllNumbers is declared to have maximum index 1 (minimum 0) in the first dimension !

Also, the code that you have till now, prints 2601 numbers (51 * 51), one number per row because you use `println`.

To generate 2 rows of 50 random numbers :
Code: java

`for (i = 0; i < 2; i++)        {        for (j = 0; j < 50; j++)                {            AllNumbers [i] [j] = RandomNum.nextInt (100);            System.out.print (AllNumbers[i][j] + " ");        }        System.out.println ();    }}`

 All times are GMT +5.5. The time now is 01:26.