Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scanner s = new Scanner(System.in);
- double amount;
- String from, to;
- double usdToBgn = 1.72;
- double eurtobgn = 1.9558;
- System.out.print("Amount: ");
- amount = s.nextDouble();
- System.out.print("From: ");
- from = s.next();
- System.out.print("To: ");
- to = s.next();
- double result;
- if (from.equals(to)) {
- result = amount;
- } else if (from.equals("USD") && to.equals("BGN")) {
- result = amount * usdToBgn;
- } else if (from.equals("USD") && to.equals("EUR")) {
- result = amount * usdToBgn / eurtobgn;
- } else if (from.equals("BGN") && to.equals("USD")) {
- result = amount / usdToBgn;
- } else if (from.equals("BGN") && to.equals("EUR")) {
- result = amount / eurtobgn;
- } else if (from.equals("EUR") && to.equals("BGN")) {
- result = amount * eurtobgn;
- } else if (from.equals("EUR") && to.equals("USD")) {
- result = amount * eurtobgn / usdToBgn;
- } else {
- System.out.println("Unknown conversion");
- return;
- }
- System.out.printf("Result: %.4f\n", result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement