Write Java program which calculator your annual expenses
import jdk.internal.util.xml.impl.Input;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double total = 0;
double value;
while (true) {
try {
System.out.print("Enter a value(negative to stop): ");
value = Double.parseDouble(in.nextLine());
if (value < 0) {
break;
}
total += value;
} catch (Exception e) {
}
}
System.out.println("Total value: " + total);
}
}
Comments
Leave a comment