Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

Java Four Calculation Double Number

Java Four Calculation Double Number

This tutorial describe how to do four calculation (addition, substraction, multiplication and division) in java using a simple example that can be created and run by Notepad, Geany, Sublime Text, Eclipse , Netbean …

Code Tested on :

  • Oracle JDK 8
  • Sublime Text 3
  • Windows 7
  • AMD A4 quadcore with 4GB of RAM
  • Compiling using command line with command prompt

Java Four Calculation Double Screen shot

Java Four Calculation Double Number Script

Create a file called MathFour.java using code below
and run in Command promt

javac MathFour.java
java MathFour

Full Code

[java]
import java.io.*;
/*
Created By Sanjay
Difficulty : Beginner Level
Description : It will take two input and and output 4 result
addition, substraction, multiplication and division
*/
class MathFour{
public static void main(String args[]) throws Exception {
double a,b;
double add,sub,multi,div;
InputStreamReader is=new InputStreamReader(System.in);
BufferedReader x=new BufferedReader(is);
System.out.println(“Enter First No. : “);
a=Double.parseDouble(x.readLine());
System.out.println(“Enter Second No. : “);
b=Double.parseDouble(x.readLine());
add=a+b;
System.out.println(“Addition : “+ add);
sub=a-b;
System.out.println(“Substration : “+ sub);
multi=a*b;
System.out.println(“Multiplication : “+ multi);
div=a/b;
System.out.println(“Division : “+ div);
}
}
[/java]

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments