About 1,600,000 results
Open links in new tab
  1. How to use formatting with printf correctly in Java

    Jan 19, 2013 · How to use formatting with printf correctly in Java Asked 12 years, 9 months ago Modified 7 years, 1 month ago Viewed 59k times

  2. java - Can a return statement be formatted like a printf ... - Stack ...

    I am new to java, so please be patient with me if this is a "stupid" question. Is there a way to format a return statement similar to printf("%d", a)? Here's a snippet of my code thus far. pub...

  3. How to print a float with 2 decimal places in Java?

    You can use the printf method, like so: System.out.printf("%.2f", val); In short, the %.2f syntax tells Java to return your variable (val) with 2 decimal places (.2) in decimal representation of a …

  4. java - What printf conversion should be used for boolean values ...

    Feb 16, 2025 · I know it's a very simple question, but I would like to know the string format for the boolean type. For instance, below shows the string formats for integer, string and float. What …

  5. Is there a good reason to use "printf" instead of "print" in java?

    Feb 14, 2009 · System.out.printf("a: %d b: %d\n", a, b); Also, writting Java applications doesn't necessarily mean writing GUI applications, so when writing console applications, one would …

  6. java - How can I pad an integer with zeros on the left? - Stack …

    How do you left pad an int with zeros when converting to a String in java? I'm basically looking to pad out integers up to 9999 with leading zeros (e.g. 1 = 0001).

  7. difference between printf and println in java? - Stack Overflow

    Feb 27, 2015 · Just came to know that java does has a method named printf, then what is the difference between printf & println?

  8. java - Limiting the number of characters in a string, and chopping …

    I need to create a summary table at the end of a log with some values that are obtained inside a class. The table needs to be printed in fixed-width format. I have the code to do this already, bu...

  9. How to print color in console using System.out.println?

    If the console support (e.g. Eclipse Java console) customizing color of stdout/stderr, then you can use System.out.println for one color and System.err.println for another color.

  10. java - Print character multiple times - Stack Overflow

    How can I print a character multiple times in a single line? This means I cannot use a loop. I'm trying to print " _" multiple times. I tried this method but it's not working: System.out.println...