/*<br /> * To change this template, choose Tools | Templates<br /> * and open the template in the editor.<br /> */</p><p>package com.ndk.javainput;</p><p>import java.util.Scanner;<br />/**<br /> *<br /> * @author Ndk<br /> */<br />public class input<br />{</p><p> //非負Int值得輸入<br /> /*<br /> *<br /> * @return 不小於零的整數<br /> * int param = input.unsignedInt();<br /> */<br /> public static int unsignedInt()<br /> {<br /> for(;;)<br /> {<br /> try<br /> {<br /> Scanner SC=new Scanner(System.in);<br /> int a=SC.nextInt();</p><p> if(a<0)<br /> {<br /> System.out.println("您的輸入格式有誤!!/n請重新輸入");<br /> continue;<br /> }<br /> else<br /> {<br /> return a;<br /> }<br /> }<br /> catch(Exception es)<br /> {<br /> System.out.println("您的輸入格式有誤!!/n請重新輸入");<br /> continue;<br /> }<br /> }<br /> }</p><p> //大於零的整數<br /> /*<br /> * @return<br /> * int param = input.moreZeroInt();<br /> */</p><p> public static int moreZeroInt()<br /> {<br /> for(;;)<br /> {<br /> try<br /> {<br /> Scanner SC=new Scanner(System.in);<br /> int a=SC.nextInt();</p><p> if(a<=0)<br /> {<br /> System.out.println("您的輸入格式有誤!!/n請重新輸入");<br /> continue;<br /> }<br /> else<br /> {<br /> return a;<br /> }<br /> }<br /> catch(Exception es)<br /> {<br /> System.out.println("您的輸入格式有誤!!/n請重新輸入");<br /> continue;<br /> }<br /> }<br /> }</p><p> public static String inputStr()<br /> {<br /> for(;;)<br /> {<br /> try<br /> {<br /> Scanner SC=new Scanner(System.in);<br /> String a=SC.next();</p><p> return a;</p><p> }<br /> catch(Exception es)<br /> {<br /> System.out.println("您的輸入格式有誤!!/n請重新輸入");<br /> continue;<br /> }<br /> }<br /> }</p><p> public static double unsignedDouble()<br /> {<br /> for(;;)<br /> {<br /> try<br /> {<br /> Scanner SC=new Scanner(System.in);<br /> double a=SC.nextDouble();</p><p> if(a<=0.0D)//?<br /> {<br /> System.out.println("您的輸入格式有誤!!/n請重新輸入");<br /> continue;<br /> }<br /> else<br /> {<br /> return a;<br /> }<br /> }<br /> catch(Exception es)<br /> {<br /> System.out.println("您的輸入格式有誤!!/n請重新輸入");<br /> continue;<br /> }<br /> }<br /> }</p><p> public static double moreZeroDouble()<br /> {<br /> for(;;)<br /> {<br /> try<br /> {<br /> Scanner SC=new Scanner(System.in);<br /> double a=SC.nextDouble();</p><p> if(a<0.0D)<br /> {<br /> System.out.println("您的輸入格式有誤!!/n請重新輸入");<br /> continue;<br /> }<br /> else<br /> {<br /> return a;<br /> }<br /> }<br /> catch(Exception es)<br /> {<br /> System.out.println("您的輸入格式有誤!!/n請重新輸入");<br /> continue;<br /> }<br /> }<br /> }</p><p>}<br />
方法摘要
static java.lang.String inputStr()
static double moreZeroDouble()
static int moreZeroInt()
static double unsignedDouble()
static int unsignedInt()
有問題請聯系我 謝謝