-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
28 lines (21 loc) · 722 Bytes
/
Main.java
File metadata and controls
28 lines (21 loc) · 722 Bytes
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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double sum = 0;
int counter = 1;
do{
System.out.println("Enter number #" + counter) ;
String nextNumber = scanner.nextLine();
try {
// int number = Integer.parseInt(nextNumber);
double number = Double.parseDouble(nextNumber);
counter++;
sum += number;
}catch (NumberFormatException nfe){
System.out.println("Invalid number");
}
}while(counter<=5);
System.out.println("Sum of 5 integers is " + sum);
}
}