-
Notifications
You must be signed in to change notification settings - Fork 8
/
LoopsEndingRemembering.java
38 lines (34 loc) · 1.14 KB
/
LoopsEndingRemembering.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
32
33
34
35
36
37
38
import java.util.Scanner;
public class LoopsEndingRemembering {
public static void main(String[] args) {
// program in this project exercises 36.1-36.5
// actually this is just one program that is split in many parts
Scanner reader = new Scanner(System.in);
System.out.println("Type numbers: ");
double sum = 0;
int i = 0;
int even = 0;
int odds = 0;
while (true){
int number = Integer.parseInt(reader.nextLine());
if (number == -1){
break;
}
sum += number;
i++;
if( number % 2 == 0){
even++;
}else{
odds++;
}
}
System.out.println("Thank you and see you later!");
int intsum = (int)sum;
System.out.println("The sum is " + intsum);
double average = sum / i;
System.out.println("How many numbers: " + i);
System.out.println("Average: "+ average);
System.out.println("Even numbers: " + even);
System.out.println("Odd numbers: " + odds);
}
}