Computer Science, asked by hhujggf, 1 year ago

Write a program to accept any 10 numbers. Print the sum of only the negative numbers.

Answers

Answered by Anonymous
22

import java.util.*;

public class Sum_Negative

{

public static void main(String args[])

{

Scanner in = new Scanner(System.in);

int a=1,n,s=0;

System.out.println("Enter any 10 numbers:");

while(a<=10)

{

n=in.nextInt();

if(n<0)

s=s+n;

a++;

}

System.out.println("The sum of the numbers ="+s):

}

}

Answered by sreemoyeegupta2007
3

Answer:

import java.util.*;

class negative

{

public static void main(String args[])

{

Scanner in = new Scanner(System.in);

int a=1,n,s=0;

System.out.println("Enter any 10 numbers:");

while(a<=10)

{

n=in.nextInt();

if(n<0)

s=s+n;

a++;

}

System.out.println("The sum of the numbers ="+s):

}

}

Explanation:

hope it helps....

Similar questions