write
a Program in
Java to accept any 10 numbers
Print the sum of the negitive numbers
Answers
Answer:
public static void main( String args[] ) {
int negs = evens = odds = 0;
Scanner in = new Scanner( System.in );
int val = 0;
System.out.println( “Enter numbers; terminate list with 0” );
while ((val = in.nextInt()) != 0) {
if (val < 0) {
negs += val;
Answer:
class example
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int number,negative=0,positive_even=0,positive_odd=0;
while(true)
{
System.out.print("Enter number : ");
number=in.nextInt();
if(number>0)
{
if(number%2==0)
{
positive_even=positive_even+number;
}
else
{
positive_odd=positive_odd+number;
}
}
else if(number<0)
{
negative=negative+number;
}
else
{
break;
}
}
System.out.println("Sum of negative numbers : "+negative);
System.out.println("Sum of positive even numbers : "+positive_even);
System.out.println("Sum of positive odd numbers : "+positive_odd);
}
}