Home Answers Viewqa Java-Beginners How to program an application for?

 
 


Jasmine
How to program an application for?
1 Answer(s)      3 years ago
Posted in : Java Beginners

How do you write an application to count the number of both odd and even integers of several positive integerss? Then the final display is the total of how many odd numbers were entered and the total of how many even numbers were entered?
View Answers

May 27, 2010 at 10:57 AM


Hi Friend,

Try the following code:

import java.util.*;

class CountEvenAndOdd{
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.println("Enter 15 numbers");
int even=0,odd=0;
for(int i=1;i<=15;i++){
int num=input.nextInt();
if(num%2==0){
even++;
}
else{
odd++;
}
}
System.out.println("Number of Odds= "+odd);
System.out.println("Number of evens= "+even);
}
}

Thanks









Related Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.