• December 13th, 2011, 08:14 AM
markxclinton
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);
}
}
}"

• December 13th, 2011, 08:18 AM
KevinWorkman
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?
• December 14th, 2011, 11:47 PM
cafeteria84
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
• December 14th, 2011, 11:58 PM
Mr.777
Quote:

Originally Posted by cafeteria84
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.