Answer to Question #200135 in Java | JSP | JSF for Oliyad

Question #200135

Write Java program which calculator your annual expenses


1
Expert's answer
2021-05-28T18:44:53-0400
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);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS