SaveText.Ru

Без имени
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         System.out.println(sumFunction());
  10.     }
  11.  
  12.     public static double sumFunction() {
  13.         int n;
  14.         double sum = 0;
  15.         System.out.println("Amount of numbers:");
  16.         Scanner in = new Scanner(System.in) ;
  17.         n = in.nextInt();
  18.         for (int i = 0; i < n; i++ ) {
  19.             System.out.println(i+1 + " number is:");
  20.             sum += in.nextInt();
  21.  
  22.         }
  23.         return sum;
  24.     }
  25. }

Share with your friends:

Print