Java Lecture-4 04-Aug - Control Flow
Java Lecture-4 04-Aug - Control Flow
Lecture 4 04-Aug-2024
Practice Problems
import java.util.*;
class HelloWorld {
System.out.println("Enter Age");
if(gender.equals("M"))
if(age<18){
else{
else{
if(age<18){
else{
}
}
OUTPUT -:
class LoopsInJava {
System.out.println("For loop");
int n = 5;
System.out.println("Java is fun");
OUTPUT -:
3. Write a program to demonstrate the use of the Switch Case Statement.
class SwitchCase {
String size;
switch (number) {
case 29:
size = "Small";
break;
case 42:
size = "Medium";
break;
case 44:
size = "Large";
break;
case 48:
break;
default:
size = "Unknown";
break;
}
4. Write a program to demonstrate the use of for each loop.
class ForEach {
System.out.println("For-Each Loop");
System.out.println(number);
class While {
System.out.println("While loop");
int i=1;
while(i<=5){
System.out.println(i);
i++;
System.out.println("Do-While loop");
int j=1;
do{
System.out.println(j);
j++;
}while(j<=10);