Flowcharts and Conditional Statments Flashcards
1
Q
What is the Euclids Algorithm?
A
- First Algorithm
- Computes HCF
2
Q
What is conditional statments?
A
- Used to selectively run different sections of program code
- Depending on a condition
- If file opener button clicked
- Then open file explorer
3
Q
How do you use if statments in java
A
```java
class Main {
public static void main(String[]args){
int special_number = 90; if (special_number == 90) { System.out.println('HIIIII') } else { System.out.print('GOHOME') }
}
}
~~~
4
Q
How do you use switch statments
A
```java
class Main {
public static void main(String[]args){
int day = 5; switch(day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesday"); break; case 4: System.out.println("Thursday"); break; case 5: System.out.println("Friday"); break; case 6: System.out.println("Saturday"); break; case 7: System.out.println("Sunday"); break; default: System.out.println("Invalid day"); break; }
}
}
~~~
5
Q
What is the ?: notation and how do you use it?
A
- ? = if .. then
- : = x or y based on ?
```java
class Main {public static void main(String[] args) {int age = 18; String message = (age >= 18) ? "You are an adult" : "You are not an adult"; System.out.println(message);
}
}
~~~
6
Q
What is a condition and what is the syntax for all the conditions?
A
- A test which uses relational operators
- To compare two items
- Never compare a constant with a constant as constants never change
7
Q
What are compound conditions?
A
- Consists of more than one term
- Consists of normal relations joined together into an expression using the logic concepts AND and OR
```java
AND == &&
OR == ||
NOT == !
~~~
8
Q
A