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);
}
}

Recommended Answers

All 9 Replies

bit confused here. what is your actual question?

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

using

System.out.printf

to format your output

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

replace your last 4 print statements with printf. go through this site System.out.printf.htm should help you understand how to use printf

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

like this.

System.out.printf("Result of Multiplication: %.9f\n" , multiply);

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.