JAVA中控制台的輸入資料的JAR包(用來實現輸入的一個類 已經上傳..需要的請下載)

來源:互聯網
上載者:User

/*<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()

有問題請聯系我 謝謝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.