Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- System.out.println("Example1 : Comma Seperators");
- double amount = 1234567.89;
- System.out.printf("%,f\n",amount);
- System.out.printf("%,.2f\n", amount);
- System.out.println("\nExample2 : Comma Seperators");
- double pay = 5000.0, yearpay = pay*12;
- System.out.printf("Your annual pay is:%,.2f\n", yearpay);
- System.out.println("Example3: Comma Sperators with Integers");
- int num = 20000;
- System.out.printf("The number is:%,10d\n",num);
- System.out.println("\n\nExample4 : Padding Numbers with Leading Zeros");
- double num2 = 123.4;
- System.out.printf("The number is:%08.1f\n", num2);
- System.out.println("\n Example5 : Left Justifying Numbers");
- int n1 = 123, n2 = 12, n3 =45678, n4 = 456, n5 = 1234567, n6 = 1233;
- System.out.printf("%-8d%-8d\n",n1, n2);
- System.out.printf("%-8d%-8d\n",n3, n4);
- System.out.printf("%-8d%-8d\n",n5, n6);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement