if else Flashcards
Correct the following:
if ( grade >= 60 ) ;
logic error, in if-else statement you must not include a semicolon after “if” nor after “else”.
What makes a one way selection in an if-else statement/program?
it includes only the if statement without the else
ex:
if (grade >= 90 )
System.out.println( “pass”) ;
System.out.println(“end.”) ;
if you want to add two messages to be printed after the if statement what do you?
you put them in a block via ( { ), ex:
if (grade >= 90 ){
System.out.println( “pass”) ;
System.out.println(“congrats.”) ;
}
System.out.println(“done.”) ;
Correct the following:
if ( grade >= 60) ;
System.out.println(“bark bark.”) ;
else
System.out.println(“meow.”) ;
compile error, when we put a semicolon after an if statement and there is an else statement after it then it is a compile error.
T/F: writing [ default : ] in a switch code is optional.
TRUE
T/F: you can use a switch code to write an if-else code.
true
How to write a switch code
switch ( — )
{
case —— :
System.out.println(“”) ;
break ;
}
You are not allowed to use a switch code on ________ or _________ variable.
boolean, double
T/F: You are allowed to use int, char, and string variable for a switch code.
true
T/F: you have to write a break for a switch code.
false, you dont have to.
T/F: Order doesn’t matter in a switch code as long as they’re numbered.
false, order of the cases does matter, and the numbering doesn’t.
What is th purpose of Math.random() ?
it gives you a random number within the range of (0 - one digit less than the number you multiplied it by)
guess the range:
Math.random() * 100
0 - 99
correct the following:
int num1 = Math.random() * 100 ;
int num1 = (int) (Math.random() * 100 ) ;
we must always cast the math random outcome
when you have && you skip the second statement if ……
the first is false.