Unit 2 Exam Flashcards
3 types of methods
boolean methods, a method that calculates something, input/output methods
ternary operator (?:)
a shorter way of writing an if…else
boolean expression ? what to return if true : what to return if false
<=
less than or equal to
continue
only works in loops
jumps back to the boolean expression
random number generation
(int) (Math. random() * (max - min + 1)) + min
!=
not equal to
> =
greater than or equal to
what variable types CAN’T be used with switch
CANNOT USE SWITCH ON FLOATS, LONGS, OR DOUBLES DUE TO ROUND-OFF
also cannot be used on boolean
method parameters
parameters allow for data to be passed through
separated by commas
what is a boolean expression
evaluates true or false
||
returns true if either is true
switch statements
must have a single variable and care about multiple specific values of it
when you have a variable with a known list of values to compare to
precedence
+ -
<, >, <=, >=
==, !=
&&
||
what happens if case above default doesn’t have a break
IF THE CASE ABOVE THE DEFAULT DOES NOT CONTAIN A BREAK, WILL RUN THE CODE IN THE DEFAULT AS WELL
what happens if a case doesn’t have a break
WITHOUT BREAK THE SWITCH WILL PRINT ALL OPTIONS BELOW
!
returns the opposite of
execute method
invoke, run, or call from another method
return
ends a method
boolean methods
contains no SOP, Scanner (no user input/output)
makes a decision and returns true or false
returning data with methods
change void to the type of data that needs to be returned
if a method has a non-void return type, must be saved or printed or else the value lost
using return ends the method, cannot have code below return
a method that calculates something
returns a calculated value (not void)
break
breaks out of the switch or a loop
input/output methods
format output for the user
error check user input
methods
block code that when called, performs an action
allows for splitting of long code into smaller chunks
&&
returns true if both are true