If Statements Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Write a program that allows the user to enter their age. If the age is 18 or older, print ‘You are eligible to vote.’ Otherwise, print ‘You are not eligible to vote.’

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write an example of an if, else if, and else statement

A

if (intVariable = 0){
con.println(“1 solution”);
}else if (intVariable > 0){
con.println(“2 zeros”);
}else{
con.println(“no zeros”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Function of Logic Statements

A

take two or more numbers/variables
compare
based on comparison, perform an action (or don’t)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

||

A

OR logic symbol

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Math Logic Comparison Symbols

A

== exactly equals to
!= not equal to
<= less than or equal to
>= greater than or equal to
< less than
> greater than

**note: the above symbols compare 2 numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Function of subString(#1, #2)

A

grabs specific letters from a string

** note: putting one number will not change the string

#1 is inclusive, #2 is exclusive (i.e. first letter is #0 and so on…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

AND logic symbol

A

&&

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

alternate condition check

A

else if statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

OR logic symbol

A

||

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write the general If Statement structure

A

if(somecomparisonconditionistrue){
//run the code within the squiggly brackets
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Function of “else if” Statement

A

an optional alternate condition check:

checks the statement/condition following the else if when the above if and/or else if statements are false

runs the code within the { } if true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

String Logic Comparison symbols

A

.equals()
.equalsIgnoreCase()
.length()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Write a program that will let you enter 3 sides of a triangle. If each of the three sides is less than half the perimeter, then a triangle can be formed (e.g., 2, 3, 1000 cannot form a triangle). If a triangle can be formed, find the area of the triangle using Heron’s Formula. If no triangle can be formed, say: ‘Error, can’t make a triangle’.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Write an example of a subString

A

strVariable = strWord.substring(0,2);

// code takes the first 2 letters of the word in the variable “strWord”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The students of your class are to be subdivided into 3 teams according to their first name. Names starting with A-I belong to team 1, Names starting with J-P belong to team 2, and Names starting with Q-Z belong to team 3. Write a program that lets you enter a name and place the person on a team. Ex: Moe belongs to team 2.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

&&

A

AND logic symbol

17
Q

Write an example of a CPU Logic Command

A

if(intVariable > #){
con.print(“Example”);
}

18
Q

Function of Else Statement

A

Optional default statement if all above conditions are false

runs the code within the { }