Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Sum of positive and negative numbers
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


David Ferguson
Sum of positive and negative numbers
1 Answer(s)      3 years and a month ago
Posted in : Java Beginners


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.


Advertisement
View Answers

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[10];
        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
counting the positive,negative and zero nos. - Java Beginners
counting the positive,negative and zero nos.  Create a program that will input n number, and determine the number of positive, negative
Advertisements
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
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
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
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
Find consecutive numbers whose sum is equal to input number.
Find consecutive numbers whose sum is equal to input number. In this section, you will learn how to display the consecutive natural numbers whose sum is equal... numbers which sum up to given number. Here is the code: import java.util.
Calculate sum of even and odd numbers in Java
Calculate sum of even and odd numbers In this section, you will learn how to read the file that contains even and odd numbers and calculate their sum... numbers from the file and then calculate their sum. Here is the code
Negative Leading
Negative Leading           In negative leading  you will learn how we can overlap a text using negative and positive leading values
negative infinity
negative infinity  What is negative infinity
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
Positive and negative aspects of Vehicle Tracking
Positive and negative aspects of Vehicle Tracking   .... But sometimes technology may be positive in itself but its application can... we should have pre-estimates of its fall outs. The positive aspects
sum
sum  a program to find the sum of the alternative diagit of it ex- no=123456 sum=1+3+5=9
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
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
Find sum of all the elements of matrix using Java
Find sum of all the elements of matrix using Java A matrix is a rectangular array of numbers. The numbers in the matrix are called its entries or its elements... dimensional array. Now to determine the sum of all these elements, we have
C calculate sum of first and last element of array
five numbers:1 2 3 4 5 Sum of first and last...C calculate sum of first and last element of array In this section, you will learn how to calculate sum of first and last element from the array of five
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
1-2+5-10+17-26 sum the series - Java Beginners
the negative numbers) * @param 'oddNums' holds all the odd numbers (i.e., all the positive numbers) */ public int performOperation(int begin,int end...1-2+5-10+17-26 sum the series  1-2+5-10+17-26 sum the series 
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
Sum of seris
Sum of seris  Program to find the sum of the following series using a function declaration. sum=x-(xxx)/3!+(xxxxx)/5!-(xxxxxxx)/7!+.....(xx....x)/n!. Where n and x are entered from the keyboard
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
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
sum
sum
sum
sum
sum
 

 

 

DMCA.com