Main.java 644B

1234567891011121314151617181920212223242526272829
  1. import java.util.*;
  2. /**
  3. * Created by iyasuwatts on 10/17/17.
  4. */
  5. public class Main {
  6. public static void main(String[] args){
  7. int n, sum = 0, i =0;
  8. Scanner sc = new Scanner(System.in);
  9. System.out.println("Enter numbers you want to sum");
  10. n = sc.nextInt();
  11. int a[] = new int[n];
  12. System.out.println("Enter the " +n+ "numbers ");
  13. while (i <n)
  14. {
  15. System.out.println("Enter number " + (i+1) +":");
  16. a[i] = sc.nextInt();
  17. sum += a[i];
  18. i++;
  19. }
  20. System.out.println("sum is =" +sum);
  21. }
  22. }