Level 3 - Conditionals & Loops Flashcards
1
Q
int s=1; for (int j = 3; j >= 0; j--) { s = s + j; } System.out.println(s);
A
7
2
Q
if (amHappy)
could also be written as:
A
if (amHappy == true)
3
Q
if (!amHappy)
could also be written as:
A
if (amHappy == false) //or if (amHappy != true)
4
Q
In Java, how do you test to see if string myName equals Joey?
A
if ( myName.equals(“Joey”) )
//or
if ( myName.equalsIgnoreCase(“joey”) )
//if you want to ignore case
5
Q
If ( (amHappy) && (tonight) )
could be written as:
A
if (amHappy==true && tonight==true)
6
Q
If ( (amHappy) | | (tonight) )
could be written as:
A
if (amHappy==true || tonight==true)
7
Q
What is the boolean operator for “and?”
A
&&
8
Q
What is the boolean operator for “or?”
A
||
9
Q
What is the boolean operator for “equal to?”
A
==