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

Thread: Java array problem

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java array problem

    Hello, I want to write an array method that is called ReallyOdd (int[] x) . The method will read the parameter as shown below, the function looks for the maximum odd numbers in the function if one or two maximum numbers are greater than the all the even numbers then the function return 1 else it returns 0

    For example we have ReallyOdd (new int[]{2,5,19,13,6}); in which 19,13 are greater than all even numbers. This must return 1 else 0


     
     
    Class Theodd {
    public static void main(String [] args)
      {
    //function parameter, no i/o input required
        reallyOdd(new int[]{10});
        reallyOdd (new int[]{2,5,19,13,6});
        reallyOdd (new int[]{1, 4,1,1,1,1});
     
     
      }
     
      static int reallyOdd (int[] x)
      {
     
     int iseven = 0;
        int isodd = 0;
    int max=[0];
     
        for (int i=0; i< x.length; i++)
        {
          if (x[i]%2 == 0)
           iseven[i]=x[i];
          else
           isodd[i]=x[i];
        }
     
    if (isodd[i]>max) {
    max=isodd[i];
    if(max>iseven[i]){
    return 1;
    else
    return 0;
    }
    }
     
     }  
    }
    Last edited by lokoprof; May 31st, 2014 at 09:25 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,251
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Java array problem

    Do you have any specific java programming questions?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.


    BTW Java coding conventions say that method names should start with lowercase letters.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,285
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: Java array problem

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post you code correctly.

Similar Threads

  1. [SOLVED] Game problem: java.lang.IndexOutOfBoundsException with array list
    By The_pizzaguy in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 23rd, 2013, 12:30 PM
  2. Java (2 dimensional array problem)
    By JoshuAtenista in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 21st, 2013, 06:38 AM
  3. Java 2d array problem
    By jugi in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 9th, 2012, 06:59 PM
  4. Replies: 2
    Last Post: May 13th, 2011, 04:08 AM
  5. Java Webservice problem (Array)
    By Gadge in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 10th, 2010, 11:06 AM

Tags for this Thread