Google Search

Monday, March 2, 2015

write a Java program to perform arithmetic operations

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

{

BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); float a,b,c,d,e,f;
System.out.println("Enter the numbers:"); a=Float.parseFloat(br.readLine()); b=Float.parseFloat(br.readLine()); c=a+b;

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

0 comments:

Post a Comment