This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Java Advanced Review #14 -printf Output using printf - %s ==> String argument %d ==> int argument %f ==> double argument %e ==> Scientific notation String name = "Elvis"; int id = 1111; double gpa = 4.15; // first argument is the String to be printed // remaining arguments are the variables to replace the %codes in order out.printf("%s is a wonderful person\n", name); out.printf("ID number %d, %s has GPA: %f \n\n", id, name, gpa); // args can be literals out.printf("ID number %d, %s has GPA: %f \n\n", 222, "Bob", 3.2); // rounding made easy double sam = 234.56789; out.printf("\n %f rounded to 3 decimals: %.3f \n", sam, sam); out.printf("\n %f rounded to tenths: %.1f \n", sam, sam); // left and right justification of numbers made easy //8.2 means right justify in 8 spaces including a decimal and 2 decimal places out.printf("\n %f rounded to 3 decimals:$%8.2f \n", sam, sam); // floating point output out.printf("\nScientific notation: %e \n", sam); // char can be variable or ASCII char ch = 'a'; out.printf("\nThese are A's %c %c \n\n", ch, 65); // printing in different bases made easy int num = 640; out.printf("\n%d base 10: %d", num, num); out.printf("\n%d base 8: %o", num, num); out.printf("\n%d base 16: %x", num, num);out....
View Full Document
This note was uploaded on 01/13/2011 for the course C S 315 taught by Professor Staff during the Fall '08 term at University of Texas at Austin.
- Fall '08