Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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

 
Ranch Hand
Posts: 58
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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)
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
%1f - format string with as many numbers , but *it always gives 6 decimal places*, hence that output.
 
sarvesh dikonda
Ranch Hand
Posts: 58
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5575
Eclipse IDE Windows XP Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
https://coderanch.com/t/385139/java/java/Why-System-Console-receives-null
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic