Discussion:
[問題] 有關定義變數的方式
(时间太久无法回复)
就是愛春日
2006-10-24 05:05:34 UTC
Permalink
�p�̧ڭ��IJAVA, ���Ѧb�g�@�ӵ{�����Q�n�L�X�@�Ӧr��
�X�{�Fvariable might not have been instalized
�N�کҪ�...�o�ذ��D�O�X�{�b���ܼƨS���ƭȤ~�|�o�˶�??

�b�o���O�Q�� �X�{�o�ذ��D �j���O�X�F���ت����~

���N�@�� �Ӧr���w�g�Q�کw�q�L
���W²�����{���X


String max_nam, stu_nam;
int number, stu_scor, max_socr = 0;
number = MyInput.readInt();

for ( i = 0 ; i < number ; i++ )
{
stu_nam = MyInput.readString();
stu_scor = MyInput.readInt();
if ( stu_scor > max_scor )
{
max_scor = stu_scor;
max_nam = stu_nam;
}
}


�o�˷|�X�{max_nam might not have been instalized



--
�Q�Y�o����
������

--
�� �o�H��: ���������~�{(ptt.cc)
�� From: 61.228.154.33
early bird
2006-10-24 13:51:09 UTC
Permalink
如果你if條件不成立,你就沒有initialized max_nam 這個變數
請問你是否有在if以外的地方
有用到 max_nam 例如:輸出max_nam等等
小弟我剛碰JAVA, 今天在寫一個程式中想要印出一個字串
出現了variable might not have been instalized
就我所知...這種問題是出現在該變數沒有數值才會這樣嗎??
在這邊是想問 出現這種問題 大概是出了哪種的錯誤
順代一提 該字串已經被我定義過
附上簡略的程式碼
String max_nam, stu_nam;
int number, stu_scor, max_socr = 0;
number = MyInput.readInt();
for ( i = 0 ; i < number ; i++ )
{
stu_nam = MyInput.readString();
stu_scor = MyInput.readInt();
if ( stu_scor > max_scor )
{
max_scor = stu_scor;
max_nam = stu_nam;
}
}
這樣會出現max_nam might not have been instalized
--
 ◣ ███ ███ ☆  Post by oaqe 
 ◢█ ▉▉█ █▇█ ★ From 218-165-100-39.dynamic.hinet.net 
◥█◤ ﹉ ﹍ ﹋ 月光海洋BBS 《mobbs.stut.edu.tw》 163.26.220.130 
继续阅读narkive:
Loading...