File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can anyone help me understand the reason behind the output i am getting! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Can anyone help me understand the reason behind the output i am getting! " Watch "Can anyone help me understand the reason behind the output i am getting! " New topic
Author

Can anyone help me understand the reason behind the output i am getting!

sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58



when i try to compile and run the above code from DOS based command prompt, it gives an output as follows-
100 - 100.000000

i understand anInt is printed as 100 as it is of type integer and its length is 3 (as minimum number of characters (i.e WIDTH ) must be 2 as per the format specifier %2d) but, why is aDouble printed as 100.000000. There must be just two zeroes to sum the the total no. of characters(i.e WIDTH) to 8 as Double is 64bits. So, the output should be 100.0000

And when i try to compile the same above code in Eclipse IDE its showing an error for the statement : System.console().format("%2d - %1f", anInt, aDouble);
The method format(String, Object[]) in the type Console is not applicable for the arguments (String, int, double)

Always believe in yourself
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

%1f - format string with as many numbers , but *it always gives 6 decimal places*, hence that output.
sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58

Seetharaman Venkatasamy wrote:%1f - format string with as many numbers , but *it always gives 6 decimal places*, hence that output.

Thanks Seetharaman Venkatasamy, but what is the answer to the second part of question.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

http://www.coderanch.com/t/385139/java/java/Why-System-Console-receives-null
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can anyone help me understand the reason behind the output i am getting!