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

Thread: please help.

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

    Unhappy please help.

    How can I determine the highest odd and even numbers here??


    "package oddevn;

    import java.util.*;

    public class OddEvn {

    public static void main(String[] args) {
    Scanner con = new Scanner(System.in);

    int number = 0;
    int odd=1; /not used dunno where exactly to put this
    int even=0; /not used dunno where exactly to put this


    System.out.print("Enter number: ");
    number = con.nextInt();

    System.out.print("Enter number: ");

    number = con.nextInt();
    System.out.print("Enter number: ");
    number = con.nextInt();

    System.out.print("Enter number: ");
    number = con.nextInt();

    System.out.print("Enter number: ");
    number = con.nextInt();

    if (number % 2 == 0) {
    System.out.println("Even number is :" + number);
    } else {
    System.out.println("Odd number is :" + number);
    }
    }
    }"



    please feedback.

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,170
    My Mood
    Hungover
    Thanks
    141
    Thanked 599 Times in 514 Posts

    Default Re: please help.

    Some words to the wise- use more informative post titles, otherwise people who might have helped you will simply skip over your post. We know you need help. An informative title will let other people know what you need help with. Also, when posting code, don't forget the highlight tags. And finally, this question has been asked many times before, did you do a search of the forums for previous related questions?

    That being said, what have you tried? Simply saying "dunno where to put this" isn't enough. What are those values supposed to be used for? How would you do this program by hand, without a computer?
    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!

  3. #3
    Member
    Join Date
    Nov 2011
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: please help.

    Well, the solution is pretty simple, I suggest this algorithm for the highest odd number:

    int highestOdd = Integer.MIN_VALUE;
    if (number is odd and number > highestOdd) {
    highestOdd = number;
    }

    System.out.println("The highest odd number is :" + highestOdd);

    Pretty simple!

    Spring 3
    Last edited by cafeteria84; January 22nd, 2012 at 03:03 PM.

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: please help.

    Quote Originally Posted by cafeteria84 View Post
    Well, the solution is pretty simple, I suggest this algorithm for the highest odd number:

    int highestOdd = Integer.MIN_VALUE;
    if (number is odd and number > highestOdd) {
    highestOdd = number;
    }

    System.out.println("The highest odd number is :" + highestOdd);

    Pretty simple!
    Did you not read the forum rules? Spoon feeding is not allowed. Avoid this.