In This Example We Are Trying To Create A Simple Calculator That Works With User Inputs In Command Line.Open Text File & Save As "CmdCalculator".Create The Class and Main Method Inside It.Import The Scanner Class.
Create A Scanner Object To Get The User Inputs.
Create Two Double Variables To Save Two Inputs.
Create Another Variable To Save The Answer.
import java.util.Scanner;
class CmdCalculator {
public static void main(String args[]){
Scanner MyScanner = new Scanner(System.in);
double No1,No2,Answer;
}
}
Now We Need Is Get The User Input and Do The Calculation and Print The Outputs.In The Command Prompt Use Scanner.nextDouble Method To Get The User Inputs as double Variable Rather Than Text..Complete The Coding.
import java.util.Scanner;
class CmdCalculator {
public static void main(String args[]){
Scanner MyScanner = new Scanner(System.in);
double No1,No2,Answer;
System.out.print("Enter The No1 : ");
No1 = MyScanner.nextDouble();
System.out.print("Enter The No2 : ");
No2 = MyScanner.nextDouble();
Answer = No1 + No2;
System.out.println("Addition Is : ");
System.out.print(Answer);
Answer = No1 - No2;
System.out.println("Subtraction Is : ");
System.out.print(Answer);
Answer = No1 / No2;
System.out.println("Division Is : ");
System.out.print(Answer);
Answer = No1 * No2;
System.out.println("Multiplication Is : ");
System.out.print(Answer);
}
}
Now Run The Program.It Will First Ask Two User Input As No1 and No2.You Will Get Following Outputs At The End.
Enter The No1 : 12
Enter The No2 : 4
Addition Is : 16
Subtraction Is : 8
Division Is : 3
Multiplication Is : 48
Subscribe to:
Post Comments (Atom)
JWT Token Decode Using Jquery
When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...
-
In this blog post Ill explain you the logic behind the Sri Lankan National Identity Card (NIC). Sri Lanka now has Old NIC No Format as well ...
-
In This Article I Will Demonstrate You To Create A Simple Chat Program Using Java Remote Method Invocation(RMI). Following Program Supports ...
-
In a windows form application sometimes you may want to import a excel file to a data grid view. In this blog post Ill demonstrate to you gu...
1 comment:
good job bro keep it up
Post a Comment