עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

שיעורי בית ב- JAVA

Featured Replies

פורסם

יש לי שיעורי בית ואני צריך לבנות מלבן מכוכביות (שיהיה חלול) בגודל לבחירתי חוץ מהגודל 4X4 שהיתה הדוגמא..

בחרתי בגודל 6X6 מלבן כזה:

******

* *

* *

* *

* *

******

ורשמתי את זה ככה:

public class Rectangle { 
private int width , height;
public Rectangle (int w, int h) {
width = w;
height = h;
}
public void draw (){
for (int i=1;i<=width;i++)
System.out.print("*");
System.out.println();

for (int J=1;J<=height-4;J++)
System.out.print("* ");
System.out.println();

for (int J=1;J<=height-4;J++)
System.out.print("* ");
System.out.println();

for (int J=1;J<=height-4;J++)
System.out.print("* ");
System.out.println();

for (int J=1;J<=height-4;J++)
System.out.print("* ");
System.out.println();

for (int i=1;i<=width;i++)
System.out.print("*");
System.out.println();



}

זה נכון ?

ואחר כך הייתי צריך לבנות מלבן שלם באותו גודל 6X6 רק שלם ככה:

******

******

******

******

******

******

ורשמתי ככה:

public void drawFilled (){
for (int i=1;i<=width;i++)
System.out.print("*");
System.out.println();

for (int i=1;i<=width;i++)
System.out.print("*");
System.out.println();

for (int i=1;i<=width;i++)
System.out.print("*");
System.out.println();

for (int i=1;i<=width;i++)
System.out.print("*");
System.out.println();

for (int i=1;i<=width;i++)
System.out.print("*");
System.out.println();

for (int i=1;i<=width;i++)
System.out.print("*");
System.out.println();

}

ואחר כך הייתה לי שאלה כזו:

העמס את השיטה draw כדי שתהיה אפשרות להעביר את תו הציור כפרמטר.כלומר,רוצים שתהיה אפשרות לצייר את המלבן כל פעם בתו אחר (לאו דווקא * כל הזמן)

אז רשמתי ככה :

public void draw (char n) {
for (int i=1;i<=width;i++)
System.out.print(n);

}

וב-main ככה זה נראה אצלי :




public class Program {
public static void main(String[] args) {
Rectangle r1=new Rectangle(6,6);
r1.draw();
r1.drawFilled();
r1.draw('@');


}


}


זה נכון ?

תודה מראש לעוזרים זה מאוד מאוד חשוב ואני חייב להגיש אותם בזמן...

פורסם

נראה שהפואנטה הייתה שתשתמש בלולאות דו-מימדיות, ופספסת אותה.

פורסם

כלל אצבע: אם אתה משתמש ב-copy-paste (או סתם כותב את אותו קוד שוב ושוב) כנראה עשית איפשהו טעות.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.