Write a program that asks for a number between 10 and 20 until the answer is appropriate. In case of a response less than 10, the program must indicate to the user that he must enter a larger number and in case answer greater than 20 will indicate that it must enter a smaller number.
I’ll give you the code first, I’ll explain it right after.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | package javaexamples; import java.util.Scanner; public class JavaExamples { public static void main(String[] args) { Scanner input=new Scanner(System.in); double number=0; do { System.out.print("Give a number between 10 and 20 "); number=input.nextDouble(); if(number < 10) System.out.print("bigger \\ n"); if(number > 20) System.out.print("smaller \\ n"); }while(number < 10 || number > 20); System.out.print("The number is correct"); } } |