Grasshopper Technologies |
Java Fun! - Chapter 6 - Foreign Currencyimport java.util.Scanner; public class JavaFun06bForeignCurrency { public static void main(String[] args) { Scanner ob=new Scanner(System.in); double exchange_rate = .74; // Start with the Euro double dollars = 1.00; // Start with 1 Dollar double foreign = 1.00; // Initialize the result System.out.println("This program can convert our dollar to any foreign currency"); System.out.println("Input a 0 to stop program"); System.out.print("\nInput the foreign equivalent of a dollar: "); exchange_rate=ob.nextDouble(); while (dollars != 0.0) { System.out.print("\nInput the dollar amount: "); dollars=ob.nextDouble(); if (dollars != 0.0) { foreign = exchange_rate * dollars; System.out.printf("%.2f U.S. Dollars Equal %.2f in foreign currency", dollars, foreign); System.out.println(""); } } } } run: This program can convert our dollar to any foreign currency Input a 0 to stop program Input the foreign equivalent of a dollar: .9982 Input the dollar amount: 100 100.00 U.S. Dollars Equal 99.82 in foreign currency Input the dollar amount: 2500 2500.00 U.S. Dollars Equal 2495.50 in foreign currency Input the dollar amount: 53 53.00 U.S. Dollars Equal 52.90 in foreign currency Input the dollar amount: 0 BUILD SUCCESSFUL (total time: 25 seconds) |