Write a program to accept any 10 numbers. Print the sum of only the negative numbers.
Answers
Answered by
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
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
Physics,
6 months ago
Physics,
6 months ago
Math,
1 year ago
Science,
1 year ago
Computer Science,
1 year ago