View Full Version : I want the java code please
ronax
Oct 13, 2011, 04:29 PM
Write a program that ask from the user how many integers you want to read then reads the set of integers from user, and then finds and prints the sum of even valued and odd valued integers . And also count how many even was entered by user and how many odd were entered by user.
ScottGem
Oct 13, 2011, 04:44 PM
Thank you for asking our help with your homework assignment. However, there are some rules we have for doing so.
Do not simply retype or paste a question from your book or study material
We won't do your homework questions for you. You were given the assignment for you to learn.
If you come up with your own answer or process and post it for us to critique that is acceptable. If you have some SPECIFIC questions that you couldn't find or didn't understand, we may help with that.
But this is your assignment, so show us you have at least attempted to complete it on your own.
Thank you.
ronax
Oct 13, 2011, 05:50 PM
import java.util.Scanner;
public class Q5
{
public static void main(String[]args)
{
Scanner input=new Scanner(System.in);
int a,b,c,d,e,x,I;
int sum=0;
int numEvens = 0;
int numOdds = 0;
System.out.print("How many integer you want to read:");
a=input.nextInt();
System.out.print("Enter 1 integer:");
b=input.nextInt();
System.out.print("Enter 2 integer:");
c=input.nextInt();
System.out.print("Enter 3 integer:");
d=input.nextInt();
System.out.print("Enter 4 integer:");
e=input.nextInt();
System.out.print("Enter 5 integer:");
x=input.nextInt();
System.out.println("Total Even valued integers entered are:");
System.out.println("Total Odd valued integers entered are:");
if(I%2==0)
sum+=i;
{ System.out.println("Sum of even numbers: "+sum);}
{ System.out.println("sum of Odd integer is: "+sum);
}
}
}
{
if (eachValue % 2 == 0 )
numEvens++;
else
numOdds++;
}
System.out.println("There are " + numOdds + " Odd Numbers");
{
if (eachValue % 2 != 0 )
System.out.print(eachValue + " , ");
}
}
}