|
|
|
|
# 1 |
|
משתמש - היכל התהילה
|
שוב, אותה בעיה.
כאשר אתה משתמש בIF ולא משתמש ב{} אז אם התנאי מתקיים, רק השורה הבאה תתבצע, לדוגמא: קוד:
if(x==y)
System.out.println("a");
System.out.println("b");
לעומת זאת: קוד:
if(x==y) {
System.out.println("a");
System.out.println("b");
}
אותו דבר לגבי הELSE: קוד:
if(x==y)
System.out.println("a");
System.out.println("b");
else
System.out.println("b");
אבל, קוד:
if(x==y)
System.out.println("a");
else
System.out.println("b");
קוד:
if(x==y) {
System.out.println("a");
System.out.println("b");
} else
System.out.println("b");
|
|
|
|
# 2 |
|
הוסטסניון
|
אוקיי, דבר ראשון סידרתי את השגיאה של הרנדום.
עכשיו הבעיה עם ה ELSE לפי מה שהבנתי ממך אני אמור לעשות ככה: קוד:
if (peola>='A' && peola<='C' && darga>=1 && darga<=3){
if (peola=='A' && darga==1)
randoma=0+(int)(Math.random()*11);
randomb=0+(int)(Math.random()*11);
IO.write(randoma);
IO.write("+");
IO.write(randomb);
IO.write("=");
toza=IO.readInt ("tozaa:");}
if(toza==randoma+randomb){
IO.writeln ("good");
suma=suma+5;}
else
IO.writeln ("not good, the tozaa="+randoma+randomb);
קוד:
--------------------Configuration: Hanuka - j2sdk <Default>--------------------
D:\JCreator\MyProjects\Test\Hanuka\Hanuka.java:14: variable randoma might not have been initialized
IO.write(randoma);
^
D:\JCreator\MyProjects\Test\Hanuka\Hanuka.java:19: variable toza might not have been initialized
if(toza==randoma+randomb){
^
D:\JCreator\MyProjects\Test\Hanuka\Hanuka.java:19: variable randoma might not have been initialized
if(toza==randoma+randomb){
^
D:\JCreator\MyProjects\Test\Hanuka\Hanuka.java:19: variable randomb might not have been initialized
if(toza==randoma+randomb){
^
4 errors
Process completed.
|
|
![]() |
| חברים פעילים הצופים באשכול זה: 1 (0 חברים ו- 1 אורחים) | |
| כלים לאשכול | |
| תצורת הצגה | |
|
|