Results 1 to 14 of 14
  1. #1
    JesusDaddy is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default How do I write a passing array program that determines if the value...

    How do I use a method that takes an integer array argument, and determines if the value Of the element of the array is even, and that prints the value. It also requires that I use a for loop to iterate through The array. Incorporate this method in an application that passes the array, int NUMS [] {12, 7, 52, 3, 15, 27, 6, 14, 25, 2}

    How do I know that this is a passing array?

    Java Code:
    // Programmer: David_Rivera
    
    
    public class isEven 
    {
    	public static void main( String[] args )
    	{
    		int[] Nums = {8, 16, 9, 52, 3, 15, 27, 6, 14, 25, 2, 10 };
    		for (int isEven = 0; isEven< Nums.length; isEven++) 
    		    if (Nums[ isEven] % 2 == 0)
    		    {
    			   System.out.printf( "Even %d \n", Nums [isEven]);
    			
    		}
    
    		
    		int[] array = {8, 16, 9, 52, 3, 15, 27, 6, 14, 25, 2, 10 };
    
    		System.out.println("Effects of passing reference to entire array:\n" + "The values of the original array are:" );
    
    // output original array elements
    for ( int value : array )
    System.out.printf( " %d", value );
    	modifyArray( array );
    System.out.println( "\n\nThe values of the modified array are:" );
    
    // output modified array elements
    	for ( int isEven : array )
    	System.out.printf( " %d", isEven );
    		
    	System.out.printf( "\n\nEffects of passing array element isEven:\n" +
    		"array[3] before modifyElement: %d\n", array[ 3 ] );
    	
    	modifyElement( array[ 3 ] );
    	System.out.printf( "array[3] after modifyElement: %d\n", array[ 3 ] );
    	
    }
    public static void modifyArray( int[] array2 )
    {
    for ( int isEven = 52; isEven < array2.length; isEven++ )
    	array2[ isEven ] = array2[isEven] % 2;
    }
    public static void modifyElement( int element )
    {
    element *=1;
    System.out.printf(
    "Value of element in modifyElement: %d\n", element );
    
    
    } // end method modifyElement
    } // end class isEven

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: How do I write a passing array program that determines if the value...

    How do I know that this is a passing array?
    I'm not sure what you are asking. What is a "passing array"?

    You can not modify an element in an array if you pass the element itself and not the array. The method needs to have access to the array to be able to change its contents and the index into the array to find the element to change.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    JesusDaddy is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default Re: How do I write a passing array program that determines if the value...

    I'm not sure what you are asking. What is a "passing array"?
    I have no idea because I'm still a newbie and learning but the book saids
    7.7 Passing Arrays to Methods: This section demonstrates how to pass arrays and individual array elements as arguments to methods. To pass an array argument to a method, specify the name of the array without any brackets. For example, if array hourlyTemperatures is declared as then the method call passes the reference of array hourlyTemperatures to method modifyArray. Every array object “knows” its own length (via its length field). Thus, when we pass an array object’s reference into a method, we need not pass the array length as an additional argument.
    For a method to receive an array reference through a method call, the method’s parameter list must specify an array parameter.
    I'm not quite understanding neither that's why I'm coming for help

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: How do I write a passing array program that determines if the value...

    Fine, a simple example then.

    Java Code:
    public static void doSomething(int[] arrayToUse){ // static function accepting an array as a parameter
       // ...
    }
    Java Code:
    int[] nums = {8, 16, 9, 52, 3, 15, 27, 6, 14, 25, 2, 10 };
    
    doSomething(nums); // 'pass the name of the array without any brackets'
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    JesusDaddy is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default Re: How do I write a passing array program that determines if the value...

    Quote Originally Posted by gimbal2 View Post
    Fine, a simple example then.

    Java Code:
    public static void doSomething(int[] arrayToUse){ // static function accepting an array as a parameter
       // ...
    }
    Java Code:
    int[] nums = {8, 16, 9, 52, 3, 15, 27, 6, 14, 25, 2, 10 };
    
    doSomething(nums); // 'pass the name of the array without any brackets'
    I understand that was just a piece of what the book explains but is more than that... you see I'm being ask to;
    use a method that takes an integer array argument, and determines if the value Of the element of the array is even, and that prints the value. It also requires that I use a for loop to iterate through The array. Incorporate this method in an application that passes the array, int NUMS [] {12, 7, 52, 3, 15, 27, 6, 14, 25, 2}
    so how do I know that I'm doing exactly what I'm being ask to do?

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: How do I write a passing array program that determines if the value...

    To be 100% sure you'd need to have the desired output so you can compare the output of your program to that what is expected.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    JesusDaddy is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default Re: How do I write a passing array program that determines if the value...

    Quote Originally Posted by gimbal2 View Post
    To be 100% sure you'd need to have the desired output so you can compare the output of your program to that what is expected.
    Java Code:
    Even 8 
    Even 16 
    Even 52 
    Even 6 
    Even 14 
    Even 2 
    Even 10 
    Effects of passing reference to entire array:
    The values of the original array are:
     8 16 9 52 3 15 27 6 14 25 2 10
    
    The values of the modified array are:
     8 16 9 52 3 15 27 6 14 25 2 10
    
    Effects of passing array element isEven:
    array[3] before modifyElement: 52
    Value of element in modifyElement: 52
    array[3] after modifyElement: 52
    This output? I'm not quite understanding sorry

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: How do I write a passing array program that determines if the value...

    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    JesusDaddy is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default Re: How do I write a passing array program that determines if the value...

    dude if you do not want to help than do not help me please... This is part of my final and I honestly don't have time to go back and forward with you. I'm looking for help not for you to complicate my situation. I already explain that I'm new at programming with java!
    Last edited by JesusDaddy; 12-16-2013 at 05:30 PM.

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: How do I write a passing array program that determines if the value...

    What are you talking about? He's only doing what you should have done - post the link to duplicates of your question so we may follow it and see what others have answered so far. And now I see your comment about "nobody helping you" - in the interest of not annoying Norm by responding to that like I usually do, I wish you good luck trying to figure it out yourself.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    JesusDaddy is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default Re: How do I write a passing array program that determines if the value...

    Quote Originally Posted by gimbal2 View Post
    What are you talking about? He's only doing what you should have done - post the link to duplicates of your question so we may follow it and see what others have answered so far. And now I see your comment about "nobody helping you" - in the interest of not annoying Norm by responding to that like I usually do, I wish you good luck trying to figure it out yourself.
    hey bud I will figure it out. You guys aren't the only one that know how to program. I'm eager to learn and I will with or without your help. Thank you

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: How do I write a passing array program that determines if the value...

    This is part of my final
    What does that mean? Will we be helping you cheat if we do too much of your work for you?

    Do you understand what the program is supposed to do when it executes? If not, then that part needs to be worked on. Explain what you don't understand about what the program is supposed to do?

    If you do understand what it is supposed to do, then when the program is executed, does it do what it is supposed to do?
    Last edited by Norm; 12-16-2013 at 06:01 PM.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    JesusDaddy is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default Re: How do I write a passing array program that determines if the value...

    Yes this is part of my final not the actual final but the practice to my final and I wouldn't be coming to you guys for help if I knew. Plus I want to learn what is it that it supposed to do. I'm asking to be taught not to help me cheat. If I wanted to cheat I would of had paid a programmer already but that's not what I want. I want to learn how to do the program.

    I even gave you guys the work that I did but I'm not sure if is doing what I'm being ask since I do not know what it is supposed to do.

    That's why I'm asking what is it supposed to do when it executes because I don't understand it, nor I understand the book. I have a professor that doesn't even bother to teach or explain. Why are you guys answering my question with a question? smh
    Last edited by JesusDaddy; 12-16-2013 at 06:08 PM.

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: How do I write a passing array program that determines if the value...

    I do not know what it is supposed to do.
    If a programmer doesn't know that, then it is not possible to write a program. The first step in writing a program is to get a design for what the program is supposed to do. When that has been decided, then you can write the code.

    Can you make a numbered list of what the program is supposed to do?
    For example, these would be the steps for some program:
    1) ask user for a number
    2) read user's input
    3) do the computations with that input
    4) print out the results
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 14
    Last Post: 10-12-2013, 09:40 AM
  2. Replies: 9
    Last Post: 09-22-2013, 09:01 PM
  3. Replies: 18
    Last Post: 04-20-2012, 03:26 AM
  4. Replies: 12
    Last Post: 02-08-2011, 02:58 PM
  5. Replies: 1
    Last Post: 02-08-2011, 09:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •