我的代碼如下:任務是檢查no的第一個數字是否爲零?
import java.util.*;
import java.io.*;
public class Buffer
{
public static void main(String args[]) throws Exception
{
int T;
Scanner sc = new Scanner(System.in);
T = sc.nextInt();
while(T > 0)
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(r);
String no = "";
no = br.readLine();
char ch = no.charAt(0);
if (ch == '0')
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
T--;
}
}
}
請幫我看看我的代碼,什麼是錯的到底是什麼?
我得到的輸出:
Run Time Error Exception in thread "main"<br>
顯示java.lang.NullPointerException在Buffer.main
1.哪一行是19行? 2. NPE是非常常見的錯誤,並在許多指南中詳細解釋。你看過這個錯誤是什麼意思嗎? – Carcigenicate
'if(no.matches(「0。*」))''而不是你做了那麼多工作? –
也不要在循環中打開流 –