0% found this document useful (0 votes)
7 views2 pages

Validating User Input in 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
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)
7 views2 pages

Validating User Input in 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
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

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 [Link];

class Dowhlogi {

public static void main(String args[]) {

Scanner scanner = new Scanner([Link]);

int num;

do {

[Link]("Enter a number between 1 and 10: ");

num = [Link]();

if (num < 1 || num > 10) {

[Link]("Number is out of range! Please try again.");

} else {

[Link]("You entered a valid number: " + num);

} while (num < 1 || num > 10);

[Link]("Program ended successfully.");

[Link]();

Output:\

You might also like