我需要帮助编写一个程序,该程序将接受 0 到 9 之间的数字,如果用户输入范围内的数字,我将打印数字本身与数字一样多次。示例:如果用户输入 5,则程序的输出将为“55555”。提前致谢。
import java.util.*;
import java.text.*;
public class Numbers{
public static void main(String[] arg){
Scanner sc = new Scanner(System.in);
int oneDigit = 0;
try{
Scanner reader = new Scanner(System.in);
System.out.print("Enter a number between 0 and 9: ");
oneDigit = reader.nextInt();
if (oneDigit < 0 || oneDigit > 9)
System.out.println("You did not enter a number between 0 and 9!");
else
}
catch(InputMismatchException ime){
System.out.println("You didn't enter a number.");
}
}
}