-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadNumbers .java
31 lines (25 loc) · 979 Bytes
/
ReadNumbers .java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.ArrayList;
import java.util.Scanner;
public class ReadNumbers {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList<Integer> collectNumbers = new ArrayList<Integer>();
int firstNumber = 0;
int counter = 0;
int sumOfElements = 0;
System.out.println("enter numbers");
int numbers = input.nextInt();
while(numbers != -1){
collectNumbers.add(numbers);
firstNumber = collectNumbers.get(0);
for(int index = 0; index < collectNumbers.size(); index++){
sumOfElements += collectNumbers.get(index);
if(sumOfElements >= firstNumber){
break;
}
numbers = input.nextInt();
}
System.out.printf("The sum of elements is: %d%nThe first element is: %d",firstNumber,sumOfElements);
}
}
}