Advertisement
476179

Untitled

Nov 12th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. System.out.println("Example 1 : Field Width");
  2.  
  3. double number =12345.6789;
  4. System.out.printf("the number is:%20f\n\n", number);
  5. //20 - field width
  6.  
  7.  
  8. System.out.println("Example 2 : Field Width with limited field");
  9.  
  10. double number2 = 12345.6789;
  11. System.out.printf("The number is:%1f\n\n",number2);
  12.  
  13.  
  14. System.out.println("Example 3 : Field Width With Rounding");
  15.  
  16. double num3 = 12345.6789;
  17. System.out.printf("num3 is:%12.2f\n\n", num3);
  18.  
  19.  
  20. System.out.println("Example4 : Field Width with integers");
  21.  
  22. int num4 = 200;
  23. System.out.printf("The number is: %6d\n", num4);
  24.  
  25.  
  26. System.out.println("Example5 : Columns");
  27.  
  28. double n1 = 127.899, n2 = 3465.148, n3 = 3.776;
  29. System.out.printf("%12.2f\n", n1);
  30. System.out.printf("%12.2f\n", n2);
  31. System.out.printf("%12.2f\n", n3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement