Moss Notes Java 02-02-17

Moss Notes Java 02-02-17

if statements are used to make decisions in java

if statements tell whether a statement is true or false and inputs a set of codes

based on its decision

if statements can only be true or false

&& is for if the statement meets more then one condition

Loops are statements

Loops repeat until a condition is met to break from it

a while loop executes the code until the condition no longer exists

example of a loop statement- while (userAnswer == ‘Y’) {
execute code…

a do while loop will always execute at least once because the condition is at the end of the loop

example: do { System.out.println(“Would you like to play again?”); userAnswer = in.nextline(); } while (userAnswer == ‘Y’

for loops execute a set number of times, it is most commonly used for processing arrays

arrays in java contains elements of similar java types

codes are optimized in arrays

a method is a set of code that is given a name for easy re-use

an array can store multiple values

array index values are able to access array elements

tne first element of array has index value O

the last element has index value (array size-1)

the array variable holds a reference