Help! Please!

Discussion in 'Java' started by JackDaniels, May 31, 2009.

  1. JackDaniels

    JackDaniels New Member

    Joined:
    May 31, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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.
    Help someone, please?
    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] + " ");
    			}
    		}
    	}
    
    More help please?
    }
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    I doubt if you have any java programming experience at all ! :mad:
    Look what you have written :
    Code:
    	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:
    	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 ();
    	}
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice