Reputation:
Java program that will:
This block of code below is prints the number entered by an user:
import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args) {
// Creates a reader instance which takes
// input from standard input - keyboard
Scanner reader = new Scanner(System.in);
System.out.print("Enter a number: ");
// nextInt() reads the next integer from the keyboard
int number = reader.nextInt();
// println() prints the following line to the output screen
System.out.println("You entered: " + number);
}
}
Upvotes: 2
Views: 275
Reputation: 46
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
double number;
System.out.print("Enter a number from 1.00 to 1,000.00: ");
number= reader.nextDouble();
//As long as the input is not within the range requests a new input
while (!(number>=1.00 && number<=1000.00)){
System.out.print("Input arrival!\nEnter a number from 1.00 to 1,000.00: ");
number= reader.nextDouble();
}
System.out.println("You entered: " + number);
}
note: The number range you specified corresponds to a double type
Upvotes: 1