// 程序运行时,数字是一个一个输入的
import
import
import
class Keyboard
{
private static String getEingabe()
{
String eingabe;
BufferedReader reader;
reader = new BufferedReader( new InputStreamReader( System.in ) );
try
{
eingabe = reader.readLine();
return eingabe;
}
catch ( IOException e )
{
e.printStackTrace();
}
return null;
}
public static int getInteger()
{
String eingabe;
do
{
eingabe = getEingabe();
}while(checkIntegerInput(eingabe) == false);
int zahl = Integer.parseInt( eingabe );
return zahl;
}
public static double getDouble()
{
String eingabe = getEingabe();
double zahl = Double.parseDouble( eingabe );
return zahl;
}
public static String getString()
{
String eingabe = getEingabe();
return eingabe;
}
public static boolean checkIntegerInput(String s)
{
char [] c = s.toCharArray();
for(int i = 0; i<c.length; i++)
{
int d = (int)c[i];
if(d<48 || d>57)
{
MyException e = newMyException("Invalid input, you should input all integer number");
return false;
}
}
return true;
}
}
class MyException
{
MyException(String s)
{
System.err.println(s);
System.out.println("Please try enter a new number between 5 and 15,inclusive 5 and 15.");
}
public int tryAgain()
{
return Keyboard.getInteger();
}
}
public class PrintAsterisk
{
public PrintAsterisk()
{
int [] nums = new int[5];
for(int i = 0; i<nums.length; i++)
{
System.out.println("Please input an integer number between 5 and 15, inclusive");
nums[i] = Keyboard.getInteger();
while(nums[i] > 15 || nums[i] < 5)
{
MyException e = new MyException("invalid input");
nums[i] = e.tryAgain();
}
}
for(int i = 0; i<nums.length; i++)
{
for(int j = 0; j<nums[i]; j++)
{
System.out.print("*");
}
System.out.println();
}
}
public static void main(String [] args)
{
PrintAsterisk pa = new PrintAsterisk();
}
}