+ 4
You can ask the user for a number in that range, check the input, and loop if it isn't in the right range. http://code.sololearn.com/cRT2zVdWYuBW import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Double d = -1.0; while ((d < 0.0) || (d > 100.0)) { System.out.println("Please enter a number between 0 and 100."); d = Double.parseDouble(sc.nextLine()); if ((d < 0.0) || (d > 100.0)) { System.out.println("Value out of range!"); } } System.out.println(d); } } while
9th Sep 2016, 8:40 AM
Zen
Zen - avatar