AP CSA 1.7 Exercise 1: Reading the Docs

Unit 1: Using Objects and Methods · Lesson 1.7 · Exercise 1

Reading the Docs

Application Program Interface (API) and Libraries. Write real Java, run it, and submit it to be graded against hidden test cases.

Why this one is worth doing

A library is code someone else already wrote and documented. This one asks you to call four methods you have never used, working only from what the task tells you about them.

What to write

  1. Read a line containing digits as a String, then read an integer n.
  2. Use Integer.parseInt to turn the String into an int, add n to it, and print the result.
  3. Print String.valueOf(n) joined onto the end of the original String.
  4. Print Integer.toBinaryString(n).
  5. Print Integer.MAX_VALUE.

Your program reads

A word made of digits, then an integer, each on its own line.

Your program prints

Four lines: the parsed sum, the joined String, n in binary, and the largest int Java can hold.

Worked examples

These are the cases you can see. There are more you cannot, and they use different values, so an answer that prints these numbers as constants will fail.

Example 1 input
42
8
Example 1 output
50
428
1000
2147483647
Example 2 input
7
1
Example 2 output
8
71
1
2147483647

Your answer

Main.java

Input for the Run button

Run sends whatever is in the input box below. Submitting runs your program against every test case, including hidden ones with different input.


  

  

Stuck?

Hint 1

Integer.parseInt("42") returns the int 42. The String "42" plus 1 would be "421", which is why the parse has to happen first.

Hint 2

Integer.MAX_VALUE is a constant, not a method, so there are no parentheses after it.

Hint 3

Every one of these is called on the class name, not on an object you made. That is what a class method looks like.

Where to go next

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]