I runned my arithmetic operations with double data type and i got o/p for postive,negative and decimals nos and if i am using three pont decimal no(0.0005) means i am getting as (2.5E-7 & 4.0E-4) two diff nos and this is my code

import java.io.*;
public class arithmetic 
	public static void main(String args[]) throws IOException
	double add;
	double sub;
	double multiply;
	double divide;
	BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
	System.out.print("Enter the Value of a : ");
	double a = Double.parseDouble(br1.readLine());
	System.out.print("Enter the Value of b : ");
	double b = Double.parseDouble(br1.readLine());
	add = a + b;
	sub = a- b;
	multiply = a*b;
	divide = a/b;
	System.out.print("After Airthmetic operations:\n");
	System.out.println("Result of Addition: "+add);
	System.out.println("Result of Subraction: "+sub);
	System.out.println("Result of Multiplication: "+multiply);
	System.out.println("Result of Division: "+divide);

i was asked to do airthmetic operations for all possible numerics where i got the o/p correctly for positive, negative and some decimal numbers and if i am trying for very small decimal nos like 0.0005 etc i am getting the outputs like i showed above in the bracket.

you are getting exponent representation cause the results are really large /small so

2.5E-7 = 2.5 * 10^-7 = 0.00000025
4.0E-4 = 4 * 10^-4 = 0.0004

Thanks a lot ejosiah
And one thing where should i use this "System.out.printf" or i should use instead of "println"

Thnks and i did as you said and i am getting the same o/p in a single line nothing is changed :):):)

thnks a lot ejosiah the prob is solved now and ur the best:):):):)

This article has been dead for over six months. Start a new discussion instead.