Chapter 3 Flashcards
(24 cards)
Precedence of arithmetic vs equality and relational operators?
Arithmetic operators are higher
Example of a unary operator
NOT (!) because it operates on 1 operand
Example of binary operators
AND and OR because each operates in two operands
Precedence of logical operators vs relational operators
Logical operators have a lower precedence
Logical operator precedence
NOT AND OR
Which statement checks only once
If statement or if else statement
Conditional operator example
System.out.print(“your change is “ +count+ ((count ==1)? “Dime” : “Dines”));
Statement that evaluates and expression then attempts to match the result to one of several possible cases
Switch statement
Statement used to control and go to the end o the switch statement
break;
Switch statement example
switch(option) { case 'A': ACount++; break; case 'B' BCount++; break; }
The case in which the control will transfer to it if no other case matches the value
default case
Switch Statement rules
Only have an integral type(byte, short, int, long) or char
Not be a Boolean or float or double
Implicit Boolean condition in switch statement is equality
No relational checks with a switch statement
Comparing strings
compareTo name1.compareTo(name2); Zero means equal Neg means name1 is less than name2 Pos means name1 is greater than name2
Lexicographic ordering
Uppercase come before lower case
Short strings come before longer strings
A statement that executes continuously until the condition becomes false
while loop
While loop syntax
while(condition)
statement;
What can be used to maintain a running sum?
Loop
A special input value that represents the end of input
Sentinel Value
A statement that is executed once initially and then the condition is evaluated
The do Statement
Syntax for the for statement
for(initialization; condition; increment)
statement;
Loop used for a specific number of times that can be calculated in advance
for loop
Infinite for loop
for( ; ;)
For loop rules
Initilzation left out none is performed
Condition left out means always true
Increment left out means no increment operation performed
Syntax for a if statement
If a Java reserved word Condition must be a Boolean expression Statement If(condition) Statement;