Practical-No: 3
Write programs to demonstrate use of: if statements (all forms of if statement
Switch – Case statement Different types of Loops(for,while and do..while)
5. Develop a program to use logical operators in do-while loop.
import java.util.Scanner;
class Dowhlogi {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
int num;
do {
System.out.print("Enter a number between 1 and 10: ");
num = scanner.nextInt();
if (num < 1 || num > 10) {
System.out.println("Number is out of range! Please try again.");
} else {
System.out.println("You entered a valid number: " + num);
} while (num < 1 || num > 10);
System.out.println("Program ended successfully.");
scanner.close();
Output:\