Michael T
- Member since:
- 23 Mac 2009
- Total points:
- 119 (Level 1)
Java program help I need help?
creat an application that prompts for an integer using the scanner class. write an input validtaion loop to allow only integers to be entered in the range of 1-10(inclusive). The program uses another loop to diplay the numbers counting from the input value 1. The output is to the console window . name the file CountDown
Answers (2)
-
Answerer 1
I guess you want to print the numbers in reverse order. Try this
import java.util.*;
public class CountDown
{
public static void main(String ar[])
{
Scanner sc = new Scanner(System.in);
boolean check = true;
int i=0;
while(check)
{
System.out.print("Enter a integer(1-10) :");
i = sc.nextInt();
if(i<1 || i>10)
System.out.println("Integer "+i+" is not between 1-10");
else
check = false;
}
System.out.println("Starting Count down");
for(int j=i;j>=1;j--)
System.out.println(j);
}
}
Sign in to vote!
-
Answerer 2
I am assume you have some java knowledge. This is really easy to do:
To implement the Scanner class to accept user input do the following:
Scanner numberInput = new Scanner(System.in);
int currentNumber = numberInput.nextInt(); //this is the number the user enters
if (currentNumber <= 10 && currentNumber >= 1)
{
//valid number loop
for (int i =currentNumber; i >0; i--)
System.out.println(i);
}
else
{
//not valid number
}
Sign in to vote!
None of these answers doing it for you?
Sometimes none of the answers get it just right. If so, pick "No Best Answer". Voters DO NOT get any points for voting on the No Best Answer.
Sign in to vote!