Lecture 3 and 4 - Operators and conditional statements Loops Flashcards

Break and continue

1
Q

How many types of operators are there in java ?

A

Arithmetic operators (+, -, *, /, %) double a = 7/2; //equals to 3.0, instead of 3.5

Assignment operators (+=, -=, *=, /=, %=, <<=, >>=, &amp;=,...)
x += 2; //equivalent to: x = x + 2;

Relational operators (==, !=, >=, <=, >,

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

Types of incremental and decremental operators

A

Postfix (x++, x–): The result is the value of x before the operators

Prefix (++x, –x): The result is the value of x after the operators

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

Bitwise and shift operators:

A
∼x \_\_\_\_Bitwise compliment of x
x &amp; y \_\_ Bitwise AND of x and y
x | y \_\_\_Bitwise OR of x and y
x ∧ y \_\_Bitwise XOR of x and y
x << k _Left shift
x >> k _Right shift
x >>> k Unsigned right shift
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Ternary operator:

A

The ternary operator can replace a if-else statement

Syntax:
condition ? exprTrue : exprFalse;

ex. min = (a<b></b>

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

What is a for loop used for ?

A

A for loop can be used to execute a block of statements repeatedly when the repeating time is known ex.
for(initialization; condition; incr/decr){
}

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

Example of for each in java ?

A

int []numArray = {7,2,6,0};
for(int i:numArray){
System.out.println(“number is: “ + i);
}

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

Do while and while loop difference :

A

while loop might not ever run. do-while loop runs at least once.

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

What does continue do ?

A

The continue statement skips the current iteration of a loop.

Only skips the innermost enclosing loop of the statement.

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