<< Chapter < Page Chapter >> Page >
Provide program code that illustrates some of what the student is expected to know about the increment/decrement operators. Also provides program code to illustrate some of what the student is apparently not expected to know.

Table of contents

Preface

General

This tutorial lesson is part of a series of lessons dedicated to the AP Computer Science A Exam .

The purpose of the series is to help you to better understand the Java Subset specifications for the Advanced Placement Computer Science A exam.

For example, if you access the AP Computer Science Course Description and scroll down to Appendix A titled AP Computer Science Java Subset , you will find the following specification :

3. The increment/decrement operators ++ and -- are part of the AP Java subset.

These operators are used only for their side effect, not for their value.

That is, the postfix form (for example, x++) is always used, and the operators are notused inside other expressions.

For example, a[x++] is not used.

(Note that I entered some line breaks into the above specification for clarity. Also note that this is the wording that appeared on the website on March 3,2011. It may change over time.)

May be clear to some, but not to others

While some students and their homeschool parents may know exactly what is meant by this specification, others may not. Therefore, my objective will be to elaborateon and attempt to clarify the specification from a technical viewpoint to help those students and their parents get a better understanding of where they need toconcentrate their efforts.

In this lesson, I will provide program code that illustrates some of what the student is expected to know. I will also provide program code to illustrate whatthe student is apparently not expected to know.

Viewing tip

I recommend that you open another copy of this document in a separate browser window and use the following links to easily find and view the figuresand listings while you are reading about them.

Figures

  • Figure 1 . Behavior of increment operator.
  • Figure 2 . Behavior of decrement operator.

Listings

Supplemental material

I recommend that you also study the other lessons in my extensive collection of online programming tutorials. You will find a consolidated index at www.DickBaldwin.com .

Discussion and sample code

In this section, I will present and explain sample programs that illustrate what the student does need to know and what the studentapparently doesn't need to know.

What the student apparently does need to know

Let's begin with a question. What output is produced by the program shown in Listing 1 ?

  • A. Compiler Error
  • B. Runtime Error
  • C. 5 5 8.3 8.3
  • D. 6 4 9.3 7.300000000000001
Listing 1 . Simple increment/decrement.
public class Increment01{ public static void main(String args[]){ new Worker().doWork();}//end main() }//end class definitionclass Worker{ public void doWork(){int w = 5, x = 5; double y = 8.3, z = 8.3;w++;x--; y++;z--;System.out.println(w + " " + x + " " +y + " " + z);}//end doWork() }//end class definition

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Ap computer science a, clarification of the java subset. OpenStax CNX. Oct 03, 2015 Download for free at https://legacy.cnx.org/content/col11279/1.5
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Ap computer science a, clarification of the java subset' conversation and receive update notifications?

Ask