write a Java program to perform arithmetic operations - Computer Programming

Computer Programming

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Monday, March 2, 2015

ALGORITHM:

Step 1: Read values for a and b.

Step 2: c=a+b, d=a-b, e=a*b,f=a/b

Step 3: print c,d,e and f

Step 4: Stop

PROGRAM:

import java.io.*;
class clsarith

{

public static void main(String args[])throws IOException

{

d=a-b; e=a*b; f=a/b;

System.out.println(a + " + " + b + " = " + c); System.out.println(a + " - " + b + " = " + d); System.out.println(a + " * " + b + " = " + e); System.out.println(a + " / " + b + " = " + f);
}

}

OUTPUT:

D:\JAVA>set path=c:\java\bin D:\JAVA>javac clsarith.java D:\JAVA>java clsarith

Enter the numbers: 10 5

10.0 + 5.0 = 15.0

10.0 - 5.0 = 5.0

10.0 * 5.0 = 50.0

10.0 / 5.0 = 2.0
D:\JAVA>

Search By STudents :

Java program to perform arithmetic operations

program in java for arithmetic operations

java program for + , - * / Operations