Omopss 2
Omopss 2
WAP to print all the three digit armstrong nos. Labelled break
& continue
OBJECTIVE : To make Students understand the working of different decision Making and
Looping Constructs in Java. Also introduce them to the concept of Labelled break and continue.
Description :
Give syntax and explaination for if-else, switch,for while and do_while loop along with example.
Give description for Labelled break and continue with example.
CONCLUSION: Students are expected to List the error they are facing along with their solution
REFERENCES :
1.WAPJ to print the roots of quadratic equation :
o demonstrate the working of types of operators(Bitwise, Logical and relational)using switch case. .
import java.util.Scanner; public
class OperatorDemo { public static
void main(String[] args) {
System.out.printn(“Om Gaikwad”);
Scanner scanner = new Scanner(System.in);
System.out.println("Select the type of operator to demonstrate:");
System.out.println("1. Bitwise Operators");
System.out.println("2. Logical Operators");
System.out.println("3. Relational Operators");
System.out.print("Enter your choice (1/2/3): ");
int choice = scanner.nextInt(); switch (choice)
{ case 1: demonstrateBitwiseOperators();
break; case 2:
demonstrateLogicalOperators(); break; case
3:
demonstrateRelationalOperators();
break; default:
System.out.println("Invalid choice."); break;
}
scanner.close();
}
private static void demonstrateBitwiseOperators() {
int a = 5; // 0101 in binary int b = 3; // 0011 in binary
System.out.println("Bitwise Operators Demonstration:");
System.out.println("a = " + a + " (in binary: 0101)");
System.out.println("b = " + b + " (in binary: 0011)");
System.out.println("a & b = " + (a & b) + " (in binary: " + Integer.toBinaryString(a & b) + ")");
System.out.println("a | b = " + (a | b) + " (in binary: " + Integer.toBinaryString(a | b) + ")");
System.out.println("a ^ b = " + (a ^ b) + " (in binary: " + Integer.toBinaryString(a ^ b) + ")");
System.out.println("~a = " + (~a) + " (in binary: " + Integer.toBinaryString(~a) + ")");
System.out.println("a << 1 = " + (a << 1) + " (in binary: " + Integer.toBinaryString(a << 1) +
")");
System.out.println("a >> 1 = " + (a >> 1) + " (in binary: " + Integer.toBinaryString(a >> 1) +
")");
}
private static void demonstrateLogicalOperators() {
boolean x = true; boolean y = false;
System.out.println("\nLogical Operators Demonstration:");
System.out.println("x = " + x);
System.out.println("y = " + y);
System.out.println("x && y = " + (x && y));
System.out.println("x || y = " + (x || y));
System.out.println("!x = " + !x);
System.out.println("!y = " + !y);
}
private static void demonstrateRelationalOperators() {
int a = 50; int b = 40;
System.out.println("\nRelational Operators Demonstration:");
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("a == b: " + (a == b));
System.out.println("a != b: " + (a != b));
System.out.println("a > b: " + (a > b));
System.out.println("a < b: " + (a < b));
System.out.println("a >= b: " + (a >= b));
System.out.println("a <= b: " + (a <= b));
}
Output:
System.out.println(num);
}
}
}
}
Output:
5.WAP to demonstrate the working of labelled break and continue.
System.out.printn(“Om Gaikwad”);
outerLoop:
for (int i = 2; i <= 5; i++) {
System.out.println("Outer loop iteration: " + i); for
(int j = 1; j <= 5; j++) {
System.out.println(" Inner loop iteration: " + j);
if (j == 3) {
System.out.println(" Breaking out of the outer loop"); break
outerLoop;
}
}
}
System.out.println(); outerLoop:
for (int i = 2; i <= 5; i++) { if
(i == 3) {
System.out.println("Skipping iteration of the outer loop when i is 3"); continue
outerLoop;
}
System.out.println("Outer loop iteration: " + i); for
(int j = 1; j <= 5; j++) {
System.out.println(" Inner loop iteration: " + j);
}
}
}
}
Output: