How to print formatted variables in Java

1 Answer

0 votes
package javaapplication1;

public class Example {
    public static void main(String[] args) {
        float f = 3.14f;
        int i = 63542;
        String s = "Java Programming";
	    System.out.printf("f: %.2f, i: %d, string: %s\n", f, i, s);
    }
}
 
 
/*
run:
 
f: 3.14, i: 63542, string: Java Programming
 
*/

 



answered Jan 12, 2016 by avibootz

Related questions

2 answers 255 views
1 answer 137 views
1 answer 170 views
1 answer 142 views
1 answer 122 views
122 views asked Apr 1, 2021 by avibootz
...