# Sum of positive and negative numbers

Hi

if someone could help that would be great

Write a program to read in 10 integer values and output the sum of all the positive integers and the sum of all the negative integers. November 14, 2011 at 10:53 AM

```import java.util.*;
class Numbers
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int sum1=0,sum2=0;
int num[]=new int;
System.out.println("Enter 10 numbers: ");
for(int i=0;i<num.length;i++){
num[i]=input.nextInt();
if(num[i]>0){
sum2+=num[i];
}
else{
sum1+=num[i];
}
}
System.out.println("Sum of positive numbers: "+sum2);
System.out.println("Sum of negative numbers: "+sum1);
}
}
```

Related Tutorials/Questions & Answers:
Sum of positive and negative numbers
Sum of positive and negative numbers  Hi if someone could help... the sum of all the positive integers and the sum of all the negative integers.  ...]; } } System.out.println("Sum of positive numbers: "+sum2); System.out.println
Sum of first n numbers
Sum of first n numbers  i want a simple java program which will show the sum of first n numbers....   import java.util.*; public class...; } System.out.println("Sum of Numbers from 1 to "+n+" : "+sum
read a positive real numbers from highest to lowest
read a positive real numbers from highest to lowest  write a java program that will read a sequence of 10 positive real nos. entered by the user and will print the same numbers in sorted order from lowest to highest using arrays
Dealing with negative lat/log numbers
Dealing with negative lat/log numbers  I need to run a script that will return cities that match within a certain range of the latitude and longitude. We are trying to check to make sure what we return for lat/log matches close
Calculate the Sum of three Numbers
Calculate the Sum of Three Numbers   ... . In this section you will learn how to calculate the sum of three numbers by using three...; To assign the value of the numbers define a method main. Remember we
Sum of two numbers using command line arguments in Java
Sum of two numbers using command line arguments in Java  Hi, How...? The calculate the sum of two numbers using command line arguments in Java... sum = a+b; Check complete example code at Add Two Numbers in Java. Thanks
ask user how many numbers to be inputted and determine the sum and highest number using an array in java
ask user how many numbers to be inputted and determine the sum and highest number using an array in java  ask user how many numbers to be inputted and determine the sum and highest number using an array in java
sum
sum  a program to find the sum of the alternative diagit of it ex- no=123456 sum=1+3+5=9
Negative Leading           In negative leading  you will learn how we can overlap a text using negative and positive leading values
sum
sum  s=135.............17 (mul of 1 to 17 odd numbers
sum
; sum=sum+s; if(i==n){ System.out.print(s...+"+"); } System.out.print("\nSum of the series : "+sum
ModuleNotFoundError: No module named 'positive'
ModuleNotFoundError: No module named 'positive'  Hi, My Python... 'positive' How to remove the ModuleNotFoundError: No module named 'positive... to install padas library. You can install positive python with following
Sum of integers
; } } System.out.println("Sum of even numbers: "+sumevenNo); System.out.println("Sum of odd numbers: "+sumoddNo...Sum of integers  A Java program that reads an integer value from
Prime Numbers
to enter a positive integer n, and which then creates and populates an int array with the first n prime numbers. Your program should then display the contents... a positive value for n, and should loop until they do so
A program to find the sum of odd number
A program to find the sum of odd number In this section you will learn how to find the sum of odd number in the series up to the given number in java... the console. Now here is the simple example which will help you to find the sum of odd
Calculate sum and Average in java
. Description:- In this example we are calculating sum and average of n numbers... the for loop, we have calculated the sum of all numbers. And after dividing the sum by the total number of numbers, we have determined the average of numbers
calculate sum of individual digit
calculate sum of individual digit   How calculate product of first and last digit of indiviual numbers Like a=43278 4*8=32
sum of the series
sum of the series  Program to sum the series 1+1/1!+1/2!+1/3!+....n
sum in JTable
sum in JTable  how to calculate sum from JTable's one field like total
ModuleNotFoundError: No module named 'negative-cycles'
ModuleNotFoundError: No module named 'negative-cycles'  Hi, My... named 'negative-cycles' How to remove the ModuleNotFoundError: No module named 'negative-cycles' error? Thanks   Hi, In your python
Rational Numbers
Rational Numbers   Write and fully test a class that represents rational numbers. A rational number can be represented as the ratio of two integer... static method that returns the largest common factor of the two positive
How to add two numbers in Java?
numbers in Java it will return you int value as sum of two numbers. In real world... numbers. The value will be returned as sum of the number. So, we have to define... how to sum(add) two numbers in Java. Check more tutorials at: Java
Applet for add two numbers
); add(text2); label3 = new Label("Sum of Two Numbers... numbers?   import java.awt.Graphics; import javax.swing.*; public class AddApplet extends JApplet { int sum; int x; int y; public void init
sorting numbers
sorting numbers  How to sort the numbers in ascending order   import java.util.*; class SortNumbers{ public static void main(String...=input.nextInt(); list.add(num); } System.out.println("Numbers
ModuleNotFoundError: No module named 'negative-inline-editor'
ModuleNotFoundError: No module named 'negative-inline-editor'  Hi...: No module named 'negative-inline-editor' How to remove the ModuleNotFoundError: No module named 'negative-inline-editor' error? Thanks   Hi
ModuleNotFoundError: No module named 'odoo10-addon-stock-no-negative'
ModuleNotFoundError: No module named 'odoo10-addon-stock-no-negative' ...: No module named 'odoo10-addon-stock-no-negative' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-stock-no-negative' error
ModuleNotFoundError: No module named 'odoo11-addon-stock-no-negative'
ModuleNotFoundError: No module named 'odoo11-addon-stock-no-negative' ...: No module named 'odoo11-addon-stock-no-negative' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-stock-no-negative' error
ModuleNotFoundError: No module named 'odoo11-addon-stock-no-negative'
ModuleNotFoundError: No module named 'odoo11-addon-stock-no-negative' ...: No module named 'odoo11-addon-stock-no-negative' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-stock-no-negative' error
ModuleNotFoundError: No module named 'odoo12-addon-stock-no-negative'
ModuleNotFoundError: No module named 'odoo12-addon-stock-no-negative' ...: No module named 'odoo12-addon-stock-no-negative' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-stock-no-negative' error
ModuleNotFoundError: No module named 'odoo8-addon-stock-no-negative'
ModuleNotFoundError: No module named 'odoo8-addon-stock-no-negative'  ...: No module named 'odoo8-addon-stock-no-negative' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-stock-no-negative' error
ModuleNotFoundError: No module named 'odoo9-addon-stock-no-negative'
ModuleNotFoundError: No module named 'odoo9-addon-stock-no-negative'  ...: No module named 'odoo9-addon-stock-no-negative' How to remove the ModuleNotFoundError: No module named 'odoo9-addon-stock-no-negative' error
ModuleNotFoundError: No module named 'odoo10-addon-stock-no-negative'
ModuleNotFoundError: No module named 'odoo10-addon-stock-no-negative' ...: No module named 'odoo10-addon-stock-no-negative' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-stock-no-negative' error
ModuleNotFoundError: No module named 'odoo11-addon-stock-no-negative'
ModuleNotFoundError: No module named 'odoo11-addon-stock-no-negative' ...: No module named 'odoo11-addon-stock-no-negative' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-stock-no-negative' error
ModuleNotFoundError: No module named 'odoo8-addon-stock-no-negative'
ModuleNotFoundError: No module named 'odoo8-addon-stock-no-negative'  ...: No module named 'odoo8-addon-stock-no-negative' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-stock-no-negative' error
ModuleNotFoundError: No module named 'sum'
ModuleNotFoundError: No module named 'sum'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'sum' How to remove the ModuleNotFoundError: No module named 'sum' error
ModuleNotFoundError: No module named 'sum'
ModuleNotFoundError: No module named 'sum'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'sum' How to remove the ModuleNotFoundError: No module named 'sum' error
print the even numbers between the range 100-200
print the even numbers between the range 100-200  Q ?write... the even numbers which are not divisible by 5 and 7. It also find out the sum of all...); } } } System.out.println("Sum of even numbers: "+sum
sum and average of grades
sum and average of grades  how to print a program which is sum and average of Korean (90), English(85), Mathematics(78), Biology(65), Chemistry(83
Numbers pyramid
Numbers pyramid  Hi sir, Can you please tell me how to output this using nested for loops? 1 2, 1 1, 2, 3 4, 3, 2, 1 1, 2, 3, 4, 5 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7 8, 7, 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7, 8, 9 10, 9, 8
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi, You function will take 2 numbers and the find the even numbers between
how to add to numbers in java
how to add to numbers in java  how to add to numbers in java
Add two big numbers
Add two big numbers       In this section, you will learn how to add two big numbers. For adding two numbers implement two big decimal numbers then apply the Sum() method
sum of fibonacci series
sum of fibonacci series  Write a Java program to print Fibonacci series upto n and find their sum also. 0+1+1+2+3+5+8+13+21Ă˘â?¬Â¦Ă˘â?¬Â¦Ă˘â?¬Â¦Ă˘â?¬Â¦=sum   Hi, Please see the thread Fibonacci program. Thanks