C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Introduction to Java

Currency conversion menu (USD, INR, EUR etc.) - Java Program

import java.util.Scanner;

 

public class CurrencyConverterMenu {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

 

        double amount;

        int choice;

 

        // Exchange rates (static for demonstration)

        double usdToInr = 83.25;

        double usdToEur = 0.92;

        double usdToGbp = 0.78;

        double usdToJpy = 150.45;

 

        double inrToUsd = 1 / usdToInr;

        double eurToUsd = 1 / usdToEur;

 

        System.out.println("===== Currency Converter =====");

        System.out.println("1. USD to INR");

        System.out.println("2. USD to EUR");

        System.out.println("3. USD to GBP");

        System.out.println("4. USD to JPY");

        System.out.println("5. INR to USD");

        System.out.println("6. EUR to USD");

        System.out.println("7. Exit");

        System.out.print("Enter your choice: ");

        choice = sc.nextInt();

 

        if (choice >= 1 && choice <= 6) {

            System.out.print("Enter amount: ");

            amount = sc.nextDouble();

        } else {

            System.out.println("Exiting program...");

            return;

        }

 

        switch (choice) {

            case 1:

                System.out.println("USD → INR: " + (amount * usdToInr));

                break;

 

            case 2:

                System.out.println("USD → EUR: " + (amount * usdToEur));

                break;

 

            case 3:

                System.out.println("USD → GBP: " + (amount * usdToGbp));

                break;

 

            case 4:

                System.out.println("USD → JPY: " + (amount * usdToJpy));

                break;

 

            case 5:

                System.out.println("INR → USD: " + (amount * inrToUsd));

                break;

 

            case 6:

                System.out.println("EUR → USD: " + (amount * eurToUsd));

                break;

 

            default:

                System.out.println("Invalid choice!");

        }

    }

}

Output

 
OUTPUT :
===== Currency Converter =====
1. USD to INR
2. USD to EUR
3. USD to GBP
4. USD to JPY
5. INR to USD
6. EUR to USD
7. Exit
Enter your choice: 1
Enter amount: 10

USD → INR: 832.5
 

Explanation of the Program

Import Scanner

import java.util.Scanner;

Used to take user input (choice + amount).

Predefined Exchange Rates

double usdToInr = 83.25;

double usdToEur = 0.92;

double usdToGbp = 0.78;

double usdToJpy = 150.45;

These are sample static exchange rates for demonstration.

To convert the other way:

double inrToUsd = 1 / usdToInr;

double eurToUsd = 1 / usdToEur;

Menu Options

Displays available conversions:

  1. USD to INR
  2. USD to EUR
  3. USD to GBP
  4. USD to JPY
  5. INR to USD
  6. EUR to USD

Take User Choice

choice = sc.nextInt();

If Valid Choice → Ask for Amount

amount = sc.nextDouble();

Switch–Case: Perform Conversion

Example:

System.out.println("USD → INR: " + (amount * usdToInr));

Exit if user presses option 7