import java.io.*; public class Echo {     public static void main(String[] args) throws IOException {         BufferedReader buf = new BufferedReader(                                   new InputStreamReader(System.in));         System.out.print("請輸入一列文字: ");         String text = buf.readLine();         System.out.println("您輸入的文字: " + text);     } } 我用這樣方法取得輸入,
怎麼讓用戶只能輸入數字跟小數點,如果他輸入英文字,直接不顯示出來~
而不是輸入做判斷再重新讓他輸入,

解决方案 »

  1.   

    C#中对textBox注册的事件
    private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
            {
                e.Handled = e.KeyChar < '0' || e.KeyChar > '9';
                if (e.KeyChar == (char)8)
                {
                    e.Handled = false;
                }
            }
      

  2.   

    楼主用的是控制台,不是.Net控件.