AP Computer Science - Formatting Quiz
True/False (5 each):
____ 1. The printf method can be used to display a formatted output using format specifiers.
____ 2. System.out.printf(“%.2f” + 25.444); will print 25.44
____ 3. System.out.printf(“%.2f”, 25.444); will print 25.44
____ 4. System.out.printf(“%4d”, 30); will print 2 blank spaces before the number 30.
____ 5. You can use formatting with System.out.println(“”) statements.
____ 6. System.out.printf(“%2f%10s”, 2.2, “Hello”); will display: 2.20 Hello
____ 7. System.out.printf(“%.3f”, 25.5); will display 25.500
____ 8. If you want a number formatted in scientific notation you use %s.
____ 9. System.out.printf(“format”, item1, item2, … , itemN); will format N items.
____ 10. Strings can be inserted into the formatting method by concatenating with +’s.
Short Answer:
(10 points) Write a System.out.printf statement for the double a = 24.55555 and a string s = “Start” to display: (3 spaces)24.6 Start
(40 pts) Reference: Java Programming Textbook
Solutions
(1) True
(2) False; can't use the +, need a comma.
(3) True
(4) True
(5) False
(6) False; it will print 2.200000.
(7) True
(8) False; use %e.
(9) True
(10) False
(1) System.out.printf("%5.1f%6s", a, s);
(2)
All SteemitEducation Posts
Physics
Kinematics Video, Circular Motion Video, Forces in 1 & 2 Dimensions Videos, Kinematics Full Lesson, Circular Motion and Gravitation Full Lesson, Kinematics and Forces Quiz, Forces in 1-Dimension, Forces in 2-Dimensions, Basic Physics, Kinematics, and Forces Review
Computer Science
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
SAT
Asymptotes, Composite Functions, Contest 1 - Area, Contest 1 – Winners and Solution, PEMDAS, Systems of Equations, Functions, Exponents, Contest 2 - More Functions, Contest 2 – Winners and Solution, Percents, The Interest Equation, All About Division, Contest 3 - Factoring, Contest 3 – Winners and Solution, Fractional and Negative Exponents, Basic Trig, Contest 4 - Math Vocab, Contest - 5
General Math
Basics of Algebra, Trigonometry Video, Proof of Quadratic Formula, Factoring Video, Unions and Intersections, Surface Area of a Cylinder, Substitution Video, Combinatorics Basics
Graphing from Algebra to Calculus
Algebra 1, Algebra 2, Pre-Calculus, Calculus
Piloting Airplanes
Introduction, Preflight, Requirements, Instruments, Take-Offs and Landings, Why a Plane Can Fly, Reading the Runway, Maneuvers
Other
Engineering (Isometric) Drawing, Pressure & SCUBA Diving
This post has received a 100% upvote worth $0.10 from @minnowspower thanks to: @theguruasia
MinnowsPower is not a bot, I am a Crowdfunding Hybrid
One small UpVote of Yours build MinnowsPower and MinnowsPower will Not Forget Your Support...!!!
(Limited Service Offer) Send 0.01 SBD and get $0.025 - $0.03 worth upvote from @MinnowsPower