fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. double s1 = 2.0;
  13. double s2 = 2.3;
  14. double s3 = 2.33;
  15. double s4 = 2.333;
  16.  
  17. System.out.format("s1 = %.0f%n", s1);
  18. System.out.format("s2 = %.1f%n", s2);
  19. System.out.format("s3 = %.2f%n", s3);
  20. System.out.format("s4 = %.3f%n", s4);
  21. System.out.format("s1 = %.0f; s2 = %.1f; s3 = %.2f; s4 = %.3f", s1, s2, s3, s4);
  22. }
  23. }
Success #stdin #stdout 0.06s 380160KB
stdin
Standard input is empty
stdout
s1 = 2
s2 = 2.3
s3 = 2.33
s4 = 2.333
s1 = 2; s2 = 2.3; s3 = 2.33; s4 = 2.333