1. Member
Join Date
Sep 2010
Posts
18
Rep Power
0

## Looping

public static void main(String[] args){
int oddNo;
oddNo = getOdd();
}
public static int getOdd(){
int oddNo = 0;
Scanner sc = new Scanner(System.in);

while (oddNo % 2 == 0){
System.out.print("Enter an odd number : ");
oddNo = sc.nextInt();
System.out.println("Wrong input ! ");
}
if (oddNo % 2 !=0);
System.out.print("The odd number is : " + oddNo);
return oddNo;

}

however, the output:
Enter an odd number : 10
Wrong input !
Enter an odd number : 8
Wrong input !
Enter an odd number : 9
Wrong input ! (how to remove this?)
The odd number is : 9

2. You'll want an if statement attached to this line:
Java Code:
`System.out.println("Wrong input ! ");`
...to verify whether or not the new input is odd/even.

PS: Adding [code] tags around your code is helpful to those trying to read it.

3. Member
Join Date
Sep 2010
Posts
18
Rep Power
0
i've got thanks and btw how i go about solving the following:
Write the main() method to call getNum () in order to get a series of positive integers between 1 and 9999. It will stop calling when the user enters 9999. The program will compute and display the following:
a) product of all the numbers,
b) average of all the numbers,
c) difference between the biggest and the smallest number

4. You've got the code for reading in number from a user. Now you need to add some logic to the loop where you read these numbers to do the computations as per the program requirements.
Start with a program with a loop that prompts for the next number and exits the loop when the number is the end number value.
When that works, move to the next part of the problem.

#### Posting Permissions

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