String disp;
for(int i=0; i<31 ; i++)
disp = disp + Integer.toString(i);
JOptionPane.showMessageDialog(null, disp);
錯誤給出:的Java:如何在一個循環將字符串
Calendar.java:28: error: variable disp might not have been initialized JOptionPane.showMessageDialog(null, disp);
將'String disp;'更改爲'String disp =「」;'或一些默認值 –