Computer Science, asked by iamlegend69, 3 months ago

write
a Program in
Java to accept any 10 numbers
Print the sum of the negitive numbers​

Answers

Answered by rashmisethi337
1

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;

Answered by Anonymous
1

Answer:

 † {\underline{\boxed{\frak{\pink{~Answer ~In ~ Short}}}}}† \:

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);

}

}

†{\underline{\boxed{\frak{\pink{~~AANCHAl~~}}}}}† \:

Similar questions