finderabc

Currency Converter

Sep 12th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P12_CurrencyConverter {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double sum = Double.parseDouble(scanner.nextLine());
  8.         String inputCurrency = scanner.nextLine();
  9.         String outputCurrency = scanner.nextLine();
  10.  
  11.        
  12.         if ("USD".equals(inputCurrency)) {
  13.             sum = sum * 1.79549;
  14.         } else if ("EUR".equals(inputCurrency)) {
  15.             sum = sum * 1.95583;
  16.         } else if ("GBP".equals(inputCurrency)) {
  17.             sum = sum * 2.53405;
  18.         }
  19.  
  20.         if ("USD".equals(outputCurrency)) {
  21.             sum = sum / 1.79549;
  22.         } else if ("EUR".equals(outputCurrency)) {
  23.             sum = sum / 1.95583;
  24.         } else if ("GBP".equals(outputCurrency)) {
  25.             sum = sum / 2.53405;
  26.         }
  27.  
  28.         System.out.printf("%.2f %s", sum, outputCurrency);
  29.  
  30.     }
  31. }
Add Comment
Please, Sign In to add comment