Write a short Java application that uses the Scanner class to accept a number be
ID: 673451 • Letter: W
Question
Write a short Java application that uses the Scanner class to accept a number between 1 and 10 from the user. If the number entered is between 1 and 10 (inclusive), the application will display a message “Good job! The number you entered is .” If the number entered was not between 1 and 10 (inclusive), an error message will be displayed, “The number entered was not between 1 and 10!” Take a screenshot to verify that your message is displayed successfully. Cut and paste the screenshot into a Word document and attach this document to your submission.
This question has been previosly answered by Sumit K. @ August 2, 2015 but site search yeilded no results or answers.
Explanation / Answer
import java.util.Scanner;
public class Maxof2
{
public static void main(String args[])
{
//taking value as command line argument.
Scanner in = new Scanner(System.in);
System.out.printf("Enter i Value: ");
int i = in.nextInt();
if(i<=10 && i>=0)
System.out.println("Good job! The number you entered is " +i);
else
System.out.println("The number entered was not between 1 and 10!");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.