הרשם שאלות ותשובות רשימת חברים לוח שנה הודעות מהיום

חזור   הוסטס - פורום אחסון האתרים הגדול בישראל > עיצוב גראפי, תכנות על כל שפותיו וקידום ושיווק אתרים > פורום תיכנות

   
|!|

השב
 
כלים לאשכול תצורת הצגה
ישן 14-12-06, 19:06   # 1
nanadav
הוסטסניון
 
מיני פרופיל
תאריך הצטרפות: Dec 2005
גיל: 33
הודעות: 1,946

nanadav לא מחובר  

צריך עזרה [JAVA]

שלום לכולם, יש לי עבודה להגיש, עשיתי את החלק הראשון ולפי הבדיקה יש שגיאה שאין לי מושג איך לסדר...
לצפייה בתוכנית ובשגיאה לחץ כאן
יש פה עוד משתנים שלא בשימוש כי זה רק ההתחלה של התוכנית.
תודה לעוזרים
  Reply With Quote
ישן 14-12-06, 19:19   # 2
בניה
משתמש - היכל התהילה
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
מיקום: נחושה
הודעות: 3,434

בניה לא מחובר  

אתה יכול להעתיק לפה את הקוד?
  Reply With Quote
ישן 14-12-06, 19:24   # 3
nanadav
הוסטסניון
 
מיני פרופיל
תאריך הצטרפות: Dec 2005
גיל: 33
הודעות: 1,946

nanadav לא מחובר  

ציטוט:
נכתב במקור על ידי בניה צפה בהודעה
אתה יכול להעתיק לפה את הקוד?
קוד:
התוכנית:
/*
 *
 */
public class Hanuka {
	public static void main(String[] args){
	char finish, peola;
	int darga, suma=0, sumb=0, sumc=0, randoma, randomb, toza;
	peola=IO.readChar ("press peola");
	darga=IO.readInt ("press darga:");
	if (peola>='A' && peola<='C' && darga>=1 && darga<=3){
		if (peola=='A' && darga==1)
		randoma=0>=(int)(Math.random()*11)<=10;
		randomb=0>=(int)(Math.random()*11)<=10;
		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:12: operator <= cannot be applied to boolean,int
		randoma=0>=(int)(Math.random()*11)<=10;
                                                  ^
D:\JCreator\MyProjects\Test\Hanuka\Hanuka.java:13: operator <= cannot be applied to boolean,int
		randomb=0>=(int)(Math.random()*11)<=10;
                                                  ^
2 errors

Process completed.
  Reply With Quote
ישן 14-12-06, 19:57   # 4
בניה
משתמש - היכל התהילה
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
מיקום: נחושה
הודעות: 3,434

בניה לא מחובר  

תנסה לעטוף את זה בסוגריים:
קוד:
(int)(Math.random()*11)
((int)(Math.random()*11))
  Reply With Quote
ישן 14-12-06, 20:51   # 5
mlnn
משתמש - היכל התהילה
 
mlnn's Avatar
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
מיקום: בחדר של חני
גיל: 35
הודעות: 4,417

mlnn לא מחובר  

קוד:
		if(toza==randoma+randomb)
		IO.writeln ("good");
		suma=suma+5;
		else
		IO.writeln ("not good, the tozaa="+randoma+randomb);}
איפו הסוגריים של הIF של הELSE?
גם בIF השני אני חושב ששכחת סוגריים.
__________________
.

בחורות ערומות
  Reply With Quote
ישן 14-12-06, 23:08   # 6
nanadav
הוסטסניון
 
מיני פרופיל
תאריך הצטרפות: Dec 2005
גיל: 33
הודעות: 1,946

nanadav לא מחובר  

תיקנתי לפי מה שאמרת והשגיאה נשאר והתווסף שגיאה ב else

התיקון:
קוד:
/*
 *
 */
public class Hanuka {
	public static void main(String[] args){
	char finish, peola;
	int darga, suma=0, sumb=0, sumc=0, randoma, randomb, toza;
	peola=IO.readChar ("press peola");
	darga=IO.readInt ("press darga:");
	if (peola>='A' && peola<='C' && darga>=1 && darga<=3){
		if (peola=='A' && darga==1)
		randoma=0>=((int)(Math.random()*11))<=10;
		randomb=0>=((int)(Math.random()*11))<=10;
		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:22: 'else' without 'if'
		else
                ^
D:\JCreator\MyProjects\Test\Hanuka\Hanuka.java:12: operator <= cannot be applied to boolean,int
		randoma=0>=((int)(Math.random()*11))<=10;
                                                    ^
D:\JCreator\MyProjects\Test\Hanuka\Hanuka.java:13: operator <= cannot be applied to boolean,int
		randomb=0>=((int)(Math.random()*11))<=10;
                                                    ^
3 errors

Process completed.
  Reply With Quote
ישן 14-12-06, 23:24   # 7
mlnn
משתמש - היכל התהילה
 
mlnn's Avatar
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
מיקום: בחדר של חני
גיל: 35
הודעות: 4,417

mlnn לא מחובר  

שוב, אותה בעיה.
כאשר אתה משתמש בIF ולא משתמש ב{} אז אם התנאי מתקיים, רק השורה הבאה תתבצע, לדוגמא:
קוד:
if(x==y)
System.out.println("a");
System.out.println("b");
אז במקרה הנל, רק אם x=y זה ידפיס A, וB זה תמיד ידפיס כי אין לזה שום קשר לIF.

לעומת זאת:
קוד:
if(x==y) {
System.out.println("a");
System.out.println("b");
}
זה ידפיס A וגם B רק אם התנאי מתקיים (x==y).

אותו דבר לגבי הELSE:
קוד:
if(x==y)
System.out.println("a");
System.out.println("b");
else
System.out.println("b");
יחזיר לך שגיאה, מכיוון שהIF מתקיים רק לשורה הראשונה כי אין {}.
אבל,
קוד:
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");
[ וגם אם אתה רוצה ELSE מעל לשורה תשתמש שוב ב{} ]
__________________
.

בחורות ערומות
  Reply With Quote
ישן 14-12-06, 23:38   # 8
nanadav
הוסטסניון
 
מיני פרופיל
תאריך הצטרפות: Dec 2005
גיל: 33
הודעות: 1,946

nanadav לא מחובר  

אוקיי, דבר ראשון סידרתי את השגיאה של הרנדום.
עכשיו הבעיה עם ה 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.
אם אני מוסיף {} גם ל ELSE הוא משאיר לי את אותה שגיאה שהייתה קודם לכן בELSE.
  Reply With Quote
ישן 14-12-06, 23:52   # 9
mlnn
משתמש - היכל התהילה
 
mlnn's Avatar
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
מיקום: בחדר של חני
גיל: 35
הודעות: 4,417

mlnn לא מחובר  

לא פתחת { ב:
if (peola=='A' && darga==1)
__________________
.

בחורות ערומות
  Reply With Quote
ישן 14-12-06, 23:56   # 10
nanadav
הוסטסניון
 
מיני פרופיל
תאריך הצטרפות: Dec 2005
גיל: 33
הודעות: 1,946

nanadav לא מחובר  

השגיאה של ה 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:25: '}' expected
}		
 ^
1 error

Process completed.
  Reply With Quote
השב

חברים פעילים הצופים באשכול זה: 1 (0 חברים ו- 1 אורחים)
 


חוקי פירסום
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is מופעל
סמיילים הם מופעל
[IMG] קוד מופעל
קוד HTML מכובה

קפיצה לפורום


כל הזמנים הם GMT +2. הזמן כעת הוא 11:18.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ