Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: problem with compiling

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    42
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default problem with compiling

    public class Unit8
    {
    	public static void main( String [] args )
    	{
     
    		int [] even = new int [ 100 ];
    		int [] odd = new int [ 100 ];
     
    		int randomNum;
     
    		for( int count = 0 ; count < 2 ; count++ )
    		{
    			System.out.println( count );
    			randomNum = (int) (25 * Math.random());
    			displayEvens( randomNum );
    			displayOdds( randomNum );
    		}
     
    	}
     
    	public static void displayOdds( int randomNum )
    	{
    		for( int count = 0 ; count < 100 ; count++ )
    		{
    			randomNum = 1+(int)(25*Math.random());
    			int randArr[m] = 1+(int)(25*Math.random());
    			System.out.println( randArr );
    			if(randomNum / 2 == 1)
    			System.out.println( randomNum );
    		}
     
    	}
     
    	public static void displayEvens( int randomNum )
    	{
     
    		for( int count = 0 ; count < 100 ; count++ )
    			{
    			randomNum = 1+(int)(25*Math.random());
    			int randArr[m] = 1+(int)(25*Math.random());
    			System.out.println( randArr );
    			if(randomNum / 2 == 0)
    			System.out.println( randomNum );
    			} 	
    	}
     
    }
    compile error:

    petes-MacBook-Air:java programs pkrasinski$ javac Unit8.java
    Unit8.java:26: ']' expected
    int randArr[m] = 1+(int)(25*Math.random());
    ------------^
    Unit8.java:26: illegal start of expression
    int randArr[m] = 1+(int)(25*Math.random());
    -----------^
    Unit8.java:41: ']' expected
    int randArr[m] = 1+(int)(25*Math.random());
    ------------^
    Unit8.java:41: illegal start of expression
    int randArr[m] = 1+(int)(25*Math.random());
    -----------^
    4 errors


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: problem with compiling

    Putting a variable type before a variable name makes the statement a definition:
    double varName; //  define a variable of type double

    When defining an array, you don't include the size of the array on the lefthand side of the =.
    The size of the array goes to the right of the =
    int[] anArray = new int[4]; //  define an array with 4 elements
    To assign a value to an element:
    theArray[theIndex] = theValue;

    What are you trying to do?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    42
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: problem with compiling

    Write a program that generates 100 random integers in the range 0 to 25, and stores them in an array. Then, the program should call a class method that sorts the odd numbers into an array and another method that sorts the even numbers into a separate array. Both arrays should be displayed.

    Thats the HW

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: problem with compiling

    Did you fix the errors?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Sep 2012
    Posts
    42
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: problem with compiling

    no I'm not sure how to do that in this case

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: problem with compiling

    I tried to say what the problem was and how to fix in in post #2.

    What parts of that don't you understand? Be explicit, don't say all of it.

    int randArr[m] = 1+(int)(25*Math.random());
    What is that statement supposed to do?


    To assign a value to an element in an array:
    theArray[theIndex] = theValue;
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Sep 2012
    Posts
    42
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: problem with compiling

    nvm my new compile error was just a typo. i got what you said but i still got an error all b/c of a typo. thanks

Similar Threads

  1. Compiling Java
    By TANKDS in forum Java Theory & Questions
    Replies: 6
    Last Post: February 6th, 2012, 02:05 PM
  2. Compiling
    By yavo in forum Java Theory & Questions
    Replies: 1
    Last Post: December 24th, 2011, 07:42 AM
  3. Compiling error
    By tangara in forum Java IDEs
    Replies: 3
    Last Post: September 4th, 2011, 03:00 AM
  4. Java compiling windows 7 problem
    By wiseone in forum The Cafe
    Replies: 3
    Last Post: July 26th, 2011, 03:06 AM
  5. Help with Compiling
    By w.spidey in forum Object Oriented Programming
    Replies: 10
    Last Post: September 9th, 2010, 01:48 PM