public class Solution {
    public static void main(String[] args) {
        Scanner ip = new Scanner(System.in);
        double input = 0;
        int count = 0;
        double sum = 0;
        while (input != -1) {
            System.out.print("Enter input:(-1 to stop): ");
            input = ip.nextDouble();
            if (input != -1) {
                sum = sum + input;
                ++count;
            }
        }
        System.out.println("Averager of " + count + " numbers is " + (sum / count) + " and its sum: " + sum);
        ip.close();
    }
}



OUTPUT:
Enter input:(-1 to stop): 10
Enter input:(-1 to stop): 20
Enter input:(-1 to stop): 30
Enter input:(-1 to stop): -1
Averager of 3 numbers is 20.0 and its sum: 60.0

 

相关文章:

  • 2021-06-21
  • 2021-05-18
  • 2021-06-21
  • 2021-12-29
  • 2021-06-04
  • 2022-01-12
猜你喜欢
  • 2021-10-09
  • 2022-12-23
  • 2021-10-17
  • 2021-09-08
  • 2021-11-17
  • 2021-06-12
相关资源
相似解决方案