{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Another Simple Program 2

Another Simple Program 2 - More on Operators and...

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

View Full Document Right Arrow Icon
More on Operators and Assignments PLUS: Reading Input from the Keyboard!! If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer, it will get you. -- Peter Farrar One person's constant is another person's variable. -- Alan Perlis But First... More on Operators Operator precedence - highest to lowest
Background image of page 1

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

View Full Document Right Arrow Icon
Parentheses * / % <--- performed in order from left to right + - <--- performed in order from left to right Note : Recall that + is an operator that adds 2 numbers, but it also is the string concatenation operator when one or both operands are Strings. Examples : int result = 2 * ((16 - 4) / 2); // result is set to 12 String s = 4 + "6" + 2; // s is set to "462" result = 13 % 2 - 1; // result is set to 0 result = 13 % 2 * 4; // result is set to 4 Increment and Decrement Operators The increment operator ++ adds 1 to a number o result ++; // The value stored in result is increased by 1 The decrement operator -- subtracts 1 from a number o result --; // value stored in result is decreased by 1
Background image of page 2
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}