Example: Enter a single digit number:2 You have entered number Two Enter a single digit number:4 You have entered number Four Enter a single digit number:0 You have entered number Zero the program will exit/quit..
Asked
Active
Viewed 1,633 times
-2
-
Show something which you have coded so far. – SubOptimal Jun 15 '15 at 11:21
-
`if(number == 0){ println("You have entered number one"); return; }` – moffeltje Jun 15 '15 at 11:23
-
ok but it has no conversion just basic – Megatron11 Jun 15 '15 at 11:27
3 Answers
0
import java.util.Scanner;
public class GetInputFromUser{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
System.out.print("Enter a number:");
int s = in.nextInt();
System.out.println("You entered number "+s);
}
}

Megatron11
- 39
- 7
-
You should post code as edit on question. not as answer. please see my answer as it was updated. – Alexander Jun 15 '15 at 11:34
-1
You can use bellow code for your desire input output:
Scanner conin=new Scanner(System.in);
System.out.println("Enter single digit number:");
String[] array = {"exit/quit","one", "two", "three","four","five","six","seven","eight","nine"};
int a=conin.nextInt();
if(a<10){
while (a!=0) {
System.out.println("You have entered number:"+array[a]);
a=conin.nextInt();
}
System.out.println("Program "+array[a]);
System.exit(0);
}else{
System.out.println("not allow");
System.exit(0);
}

Rafiq
- 740
- 1
- 5
- 17