Knowee
Questions
Features
Study Tools

Develop a Java program to simulate a currency converter from USD toIndian Rupees using control statements

Question

Develop a Java program to simulate a currency converter from USD to Indian Rupees using control statements

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple Java program that simulates a currency converter from USD to Indian Rupees. This program uses the Scanner class for input and if-else control statements to handle invalid input.

import java.util.Scanner;

public class CurrencyConverter {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double usdToInrRate = 74.28; // You can update this rate as per the current market rate

        System.out.println("Welcome to USD to INR converter. Please enter the amount in USD:");
        double usd = scanner.nextDouble();

        if (usd < 0) {
            System.out.println("Invalid input. Please enter a positive amount.");
        } else {
            double inr = usd * usdToInrRate;
            System.out.println("Amount in INR: " + inr);
        }
    }
}

In this program, we first import the Scanner class which we use to get the user input. We then define the conversion rate from USD to INR. We ask the user to input the amount in USD. If the user inputs a negative number, we print an error message. If the user inputs a positive number, we convert the amount to INR by multiplying it with the conversion rate and print the result.

This problem has been solved

Similar Questions

These controls are designed to govern the conversion, purchase and transfer of domestic currency into foreign currencies.

The currency from almost every country can be converted to another country's currency.TrueFalse

Which department of the RBI is responsible for issuing and managing currency in India?

Presently exchange controls are utilized of with weak economies, low exports and with low foreign currency reserves

when gov fixes the exchange rate, say 1 rupee=70 dollars, this is parity vlue right?

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.