Similar to Daffodil International University. Object oriented programming JAVA if else statement And switch case , JAVA if else statement And switch case
Similar to Daffodil International University. Object oriented programming JAVA if else statement And switch case , JAVA if else statement And switch case (20)
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Daffodil International University. Object oriented programming JAVA if else statement And switch case , JAVA if else statement And switch case
1. Our Topic is if else statement
And switch case
WELCOME TO OUR
PRESENTATION
2. Definition of if else and swetch statement:
The if-then statement is the most basic of all the
control flow statements. It tells your program to
execute a certain section of code only if a
particular test evaluates to true.
The if-then-else statement provides a secondary
path of execution when an "if" clause evaluates
to false
A switch statement checks if a variable is equal
to a list of values. The variable in the switch
statement
3. Public class ElseIf{
public static void main(String[]args){
int number=30;
if(number <30){
System.out.println("Number is lass then 30");
}
else if(number ==30){
System.out.println("Number is Equal 30");
}
else if(number <50){
System.out.println("Number is lass than 50");
}
else{
System.out.println("Number is greater then 30");
}
}}
Code for the if
else:
4. Multiple choice tests
public class mcq{
public static void main(String[] args) {
String[] multiChoice1;
Scanner input = new Scanner(System.in);
multiChoice1 = new String[5];
multiChoice1[0] = "1. Which country currently emits the most greenhouse
gases?n";
multiChoice1[1] = "blah blah";
multiChoice1[2] = "blah blah";
multiChoice1[3] = "blah blah";
multiChoice1[4] = "blah blah";String userSelect1 = multiChoice1[0];
if(userSelect1==multiChoice1[0]){
System.out.println(multiChoice1[0]);
System.out.println("A. United
States");
System.out.println("B. China");
System.out.println("C. India");
System.out.println("D. England");
System.out.println();
5. switch (uSelect1.toUpperCase()){
case "A":
uSelect1 = "United States";
System.out.println("Incorrect!nn");
break;
case "B":
uSelect1 = "China";
System.out.println("Correct!nn");
break;
case "C":
uSelect1 = "India";
System.out.println("Incorrect!nn");
break;
case "D":
uSelect1 = "England";
System.out.println("Incorrect!nn");
break;
default:
uSelect1 = "Incorrect, choice.nn";
break;
}
}// more multiple choice questions with similar structure}]