216k views
3 votes
Write a program that produces the following output (where the user may enter any positive integer under 10):______

Enter a positive integer under 10:_________

User GigaRohan
by
4.9k points

2 Answers

4 votes

Final answer:

The provided program, written in Python, prompts the user to enter a positive integer under 10 and prints it out if it's within the valid range, otherwise it notifies the user of the incorrect input.

Step-by-step explanation:

The question is asking for a simple program that prompts the user to enter a positive integer less than 10 and prints out a specific output. We can use a programming language like Python to achieve this. Below is an example of what the program might look like:

positive_integer = int(input("Enter a positive integer under 10: "))
if positive_integer > 0 and positive_integer < 10:
print("The number you entered is:", positive_integer)
else:
print("The number is not within the specified range.")

The program first asks the user to enter a positive integer. It then checks if the number is greater than 0 and less than 10 before printing it out. If the number is not within the valid range, it informs the user accordingly.

User Esteve
by
5.5k points
5 votes

Answer:

// The Scanner class is imported to allow the program receive user input

import java.util.Scanner;

// The class is defined called Solution

public class Solution {

// The main method is defined which begin program execution

public static void main(String args[]) {

// Scanner object 'scan' which receive user input from the keyboard

Scanner scan = new Scanner(System.in);

// the userInput variable is initially set to 1 (true) to allow the program continue prompting the user for input

int userInput = 1;

// while loop which continue execution as long as the userInput is greater than 0 and less than 10

while (userInput > 0 && userInput < 10){

// Prompts is displayed to the user to enter number below 10

System.out.println("Enter a positive integer under 10:__________");

// the next input is assigned to userInput

userInput = scan.nextInt();

}

}

}

Step-by-step explanation:

The above code continue prompting the user to input an integer as long as the input is greater than 0 and less than 10.

User Bogdan B
by
5.1k points