1. Home >
  2. Computers & Internet >
  3. Programming & Design >
  4. Undecided Question
Michael T Michael T
Member since:
23 Mac 2009
Total points:
119 (Level 1)

Undecided Question

Show me another »

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
  • 3 months ago
  • (Tiebreaker)

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);
    }
    }
    • 3 months ago
  • 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
    }
    • 3 months ago

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.

This question about "Java program help I … " was originally asked on Yahoo! Answers United States

Answers International

Yahoo! does not evaluate or guarantee the accuracy of any Yahoo! Answers content. Click here for the Full Disclaimer.

Help us improve Yahoo! Answers. Tell us what you think.