By LearnAllStudents Editorial Team. Source check dates are listed below.
Official resources
Try the original task
Write countRises(int[] readings). Return the number of times a reading is strictly greater than the immediately previous reading. Assume readings is non-null. For the values [2, 2, 5, 4, 7] your method should return 2.
Worked example
int countRises(int[] readings) {
int count = 0;
for (int i = 1; i < readings.length; i++) {
if (readings[i] > readings[i - 1]) {
count++;
}
}
return count;
}The first pair 2 and 2 is equal, so it contributes nothing. Only 2 to 5 and 4 to 7 increment the count. Starting at 1 gives each element a previous index.
Test the edges before submitting
An empty array and a one-element array both return zero because the loop never starts. The array [7, 5, 5] returns zero. Check that your condition uses a strict comparison and that the count is returned after the loop.
How a tutor would approach this
Bring your Java method, an input and the expected output. Trace both a typical case and an edge case.
Frequently asked questions
Does this apply to AP Computer Science Principles?
This exercise targets Java practice for AP Computer Science A. Check the separate Principles exam requirements.
Why start the index at one?
Index zero has no previous element, and the task compares adjacent values.
Should equal values count as rises?
No. Strictly greater values count.
Is the exercise an official free-response question?
It is original practice. Use College Board materials for official questions and scoring guidance.
Keep exploring your course
AP Computer Science A Practice Exam Setup
Use College Board’s current exam page to plan a practice session.
OpenAP Computer Science A Java Quick Reference
Open the Java Quick Reference linked by College Board before practising AP Computer Science A.
OpenAP Computer Science A Exam Format Guide
AP Computer Science A: 42 multiple-choice questions, four Java free-response tasks, timing and score weights.
OpenAP Computer Science A Unit 1 Practice
For AP Computer Science A Unit 1, practice distinguishing the object, the method call and the value returned.
OpenHow to Choose an AP Computer Science A Tutor
Bring a short Java program with one test case when comparing AP Computer Science A tutors.
OpenAP Computer Science A ArrayList FRQ Practice
Practice tracing and editing an ArrayList in Java.
OpenAP Computer Science A 2D Array FRQ Practice
Practice tracing two-dimensional Java arrays with separate row and column indexes.
OpenOfficial sources
- College Board AP Computer Science A exam (checked 2026-11-25)
Related pages
Try a free 30-minute demo
Work through a question with a tutor. No payment needed.
Request a free 30-minute demo