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 5 of 5

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

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

    // 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
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

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


  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    so I'm not allow to go to different forums and ask?

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

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

    Quote Originally Posted by JesusDaddy View Post
    so I'm not allow to go to different forums and ask?
    Allowed? Sure, nobody can stop you from doing it. But it's considered common courtesy to at least let people know where else you've posted your question. That way we can see what you've already been told. Otherwise we're wasting our time repeating advice or answering questions that have already been answered. People choose to help, for free, in their spare time, so wasting that time is pretty rude.

    For more info, read this: http://www.javaprogrammingforums.com...s-posting.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Quote Originally Posted by KevinWorkman View Post
    Allowed? Sure, nobody can stop you from doing it. But it's considered common courtesy to at least let people know where else you've posted your question. That way we can see what you've already been told. Otherwise we're wasting our time repeating advice or answering questions that have already been answered. People choose to help, for free, in their spare time, so wasting that time is pretty rude.

    For more info, read this: http://www.javaprogrammingforums.com...s-posting.html
    I'm sorry if you guys found it rude. Yes I did posted this in that forum but I still haven't received a reply that teaches me that I'm doing the program correctly. I'm being asked;
    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}
    and no one is helping me know if I'm doing exactly what I'm being ask to do?

Similar Threads

  1. Passing an array to the constructor!
    By Mike8 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 1st, 2013, 12:21 PM
  2. Program that determines the lagest and the smallest number
    By desiVirus in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 30th, 2013, 06:38 PM
  3. Please help with passing an array to a new class
    By axelrose in forum Object Oriented Programming
    Replies: 1
    Last Post: July 6th, 2012, 05:08 PM
  4. program that determines largest and smallest
    By Reverie in forum Loops & Control Statements
    Replies: 4
    Last Post: February 26th, 2012, 08:41 PM
  5. Replies: 1
    Last Post: December 12th, 2011, 06:03 AM