0% found this document useful (0 votes)
6 views

Java_Practical_2

The document contains practical exercises on control and looping statements in Java, authored by Sahil Badhe. It includes examples of simple if statements, if-else statements, nested if statements, switch statements, and various types of loops such as for, while, and do-while. Each section demonstrates the functionality of these statements with corresponding output.

Uploaded by

Sahil Badhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Java_Practical_2

The document contains practical exercises on control and looping statements in Java, authored by Sahil Badhe. It includes examples of simple if statements, if-else statements, nested if statements, switch statements, and various types of loops such as for, while, and do-while. Each section demonstrates the functionality of these statements with corresponding output.

Uploaded by

Sahil Badhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Practical NO :- 02

/*

Practical No:- 02

Enroll : 2206005

Name : Sahil Badhe

Title : 1. Control Statements

2. Looping statements

*/

public class Control_Statements {

public static void main(String[] args) {

int num=47;

// 1. Simple if statement

System.out.println("if statement");

if(num>0)

System.out.println("The number is Positive");

// 2. if-else statement

System.out.println("");

System.out.println("is-else statement");

if(num % 2 == 0)

System.out.println("Even Number");

else

System.out.println("Odd Number");

}
// 3. if-else-if ladder

System.out.println("");

System.out.println("if-else-if lader");

if (num > 0 && num < 10)

System.out.println("The number is a single-digit positive number.");

else if (num >= 10 && num < 100)

System.out.println("The number is a two-digit positive number.");

else

System.out.println("The number is a large positive number.");

// 4. Nested if statement

System.out.println("");

System.out.println("Nested if statement");

if (num > 0)

if (num % 5 == 0)

System.out.println("The number is positive and divisible by 7.");

else

System.out.println("The number is positive but not divisible by 7.");

}
}

else

System.out.println("The number is not positive.");

// 5. Switch statement

System.out.println("");

System.out.println("Switch case");

int day = 4;

switch (day)

case 1:

System.out.println("Sunday");

break;

case 2:

System.out.println("Monday");

break;

case 3:

System.out.println("Tuesday");

break;

case 4:

System.out.println("Wednesday");

break;

case 5:

System.out.println("Thusday");

break;

case 6:

System.out.println("Friday");
break;

case 7:

System.out.println("Saturday");

break;

default:

System.out.println("Invalide number");

break;

Out Put:-
/*

Practical No:- 02

Enroll : 2206005

Name : Sahil Badhe

Title : Looing Statement

*/

public class Loops {

public static void main(String[] args) {

// 1. For Loop

System.out.println("For Loop:");

for (int i = 1; i <= 5; i++)

System.out.println("Number : " + i);

// 2. While Loop

System.out.println("\nWhile Loop:");

int j = 1;

while (j <= 4) {

System.out.println("Number: " + j);

j++;

// 3. Do-While Loop

System.out.println("\nDo-While Loop:");

int k = 1;

do {

System.out.println("Number " + k);


k++;

} while (k <= 3);

Out Put:-

You might also like