Padd Solutions

Converted by Falcon Hive

import java.util.Scanner;

public class Sum
{
    public static void main (String[] args)
    {
        Scanner scan = new Scanner (System.in);
       
        int num, total = 0;
        int counter = 0;
        double average;

       
        System.out.println ("Enter numbers to add together. Type -1 to stop.");
        num = scan.nextInt ();
       
        while (num != -1)
        {
            total += num;
            //total += num   means total = total + num
            //average needs counter++
            counter++;
           
            System.out.println ("Enter another number to add on. -1 to stop.");
            num = scan.nextInt ();
 
        }
       
        // double = decimal, int = no decimal, integer
       
        average = (double) total / counter;
        System.out.println ("The total value of your numbers is " +total);
        System.out.println ("The average of your numbers is " +average);
    }
}

(0) Comments

Post a Comment