Advertisement
476179

Untitled

Nov 12th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. System.out.println("Example1 : Comma Seperators");
  2.  
  3. double amount = 1234567.89;
  4. System.out.printf("%,f\n",amount);
  5. System.out.printf("%,.2f\n", amount);
  6.  
  7. System.out.println("\nExample2 : Comma Seperators");
  8. double pay = 5000.0, yearpay = pay*12;
  9. System.out.printf("Your annual pay is:%,.2f\n", yearpay);
  10.  
  11. System.out.println("Example3: Comma Sperators with Integers");
  12. int num = 20000;
  13. System.out.printf("The number is:%,10d\n",num);
  14.  
  15. System.out.println("\n\nExample4 : Padding Numbers with Leading Zeros");
  16. double num2 = 123.4;
  17. System.out.printf("The number is:%08.1f\n", num2);
  18.  
  19. System.out.println("\n Example5 : Left Justifying Numbers");
  20. int n1 = 123, n2 = 12, n3 =45678, n4 = 456, n5 = 1234567, n6 = 1233;
  21. System.out.printf("%-8d%-8d\n",n1, n2);
  22. System.out.printf("%-8d%-8d\n",n3, n4);
  23. System.out.printf("%-8d%-8d\n",n5, n6);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement