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

Practical3.5 Java

The document provides a Java program that demonstrates the use of if statements, a do-while loop, and logical operators. It prompts the user to enter a number between 1 and 10, validating the input and ensuring it is within the specified range. If the input is valid, it confirms the entry; otherwise, it requests a new input until a valid number is provided.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Practical3.5 Java

The document provides a Java program that demonstrates the use of if statements, a do-while loop, and logical operators. It prompts the user to enter a number between 1 and 10, validating the input and ensuring it is within the specified range. If the input is valid, it confirms the entry; otherwise, it requests a new input until a valid number is provided.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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:\

You might also like