Review%20#14 printf - Java Advanced Review #14 -printf...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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.

Page1 / 4

Review%20#14 printf - Java Advanced Review #14 -printf...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online