This blog post is about how you can create a currency converter program in java language. As java is the powerful tool today to solve the real life programming problems. Every beginner wants to learn java and build some basic programs. These basic programs are hands on practice which really improve the problem solving ability in programming as well as able the programmer to grab the basic understanding. To get the basic understanding on any new programming language such type of programs practice helps to quickly familiar with the syntax of new language.
If you are a programmer, you probably know to make the currency converter program in C++ , C, Python or any other programming language. The logic and concept or algorithm for the currency converter program is same in all languages.
Here we will use the same algorithm to develop a currency converter program in Java language. The algorithm we will use is as under:
Algorithm of Currency Converter Program:
Step 1:Create the variables for currencies.
Step 2:Take user input in dollars.
Step 3:Multiply dollars with exchange rate.
Step 4:Display other currencies on screen.
Code of Currency Converter Program:
package com.softoset;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
float dollar;
float bp= (float) (1/1.487);
float frnc= (float) (1/0.172);
float dutchmark= (float) (1/0.584);
float yen= (float) (1/0.00955);
System.out.println("Enter the Dollars for Conversion :\n");
Scanner in=new Scanner(System.in);
dollar=in.nextFloat();
System.out.println("British Pounds :"+bp*dollar);
System.out.println("French franc :"+frnc*dollar);
System.out.println("German Dutchmark :"+dutchmark*dollar);
System.out.println("Japanese Yen :"+yen*dollar);
}
}
Output of Currency Converter Program:
Post a Comment
Feel Free to Comment Us