נבנה על ידיBuilt by Ariel Yohimovich

JavaJava
5
חלקPart 1: יסודותFoundations כ-3 שעות (כולל הפסקה)About 3 hours (with a break)

לולאותLoops

for, while, do-while ו-for-each, break ו-continue, לולאות מקוננות ומעקב אחרי משתני לולאה.

for, while, do-while and for-each, break and continue, nested loops and tracing loop variables.

כותבים בעורך שבכל תרגיל, לוחצים הרצה כדי לראות פלט, ובדיקה כדי שהבודק האוטומטי יבדוק. אפשר גם לעבוד ב-IntelliJ ולסמן פתרתי. ההתקדמות נשמרת.Write in each exercise's editor, press Run to see output and Check for the automatic checker. You can also work in IntelliJ and mark I solved it. Progress is saved.

חימום: 3 שאלותWarm-up: 3 questions

1. כמה פעמים תודפס המילה?How many times is the word printed?
main
for (int i = 0; i < 4; i++) {
    System.out.println("hi");
}

2. מה ההבדל בין while ל-do-while?What's the difference between while and do-while?

3. מה עושה continue?What does continue do?

תרגיליםExercises

תרגילExercise 1

ספירה בשורה אחתCounting on one line

הדפיסו בשורה אחת את המספרים 1 עד 10 עם רווח אחרי כל מספר, ואחר כך done בשורה חדשה.

Print the numbers 1 to 10 on one line with a space after each, then done on a new line.

איך הפלט אמור להיראות?What should the output look like?
1 2 3 4 5 6 7 8 9 10 
done
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1: for (int i = 1; i <= 10; i++)for (int i = 1; i <= 10; i++)
רמזHint 2: System.out.print(i + " "); כדי להישאר באותה שורה.System.out.print(i + " "); to stay on the same line.
לפתרוןSolution
תרגילExercise 2

סכום 1 עד 10Sum of 1 to 10

חשבו בלולאה את הסכום 1+2+...+10 והדפיסו Sum: 55.

Compute 1+2+...+10 in a loop and print Sum: 55.

איך הפלט אמור להיראות?What should the output look like?
Sum: 55
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1: int sum = 0; לפני הלולאה.int sum = 0; before the loop.
רמזHint 2: בתוך הלולאה: sum += i;.Inside the loop: sum += i;.
לפתרוןSolution
תרגילExercise 3

ספירה לאחורCountdown

עם while, הדפיסו 5, 4, 3, 2, 1 (כל מספר בשורה) ואחר כך Liftoff!.

With while, print 5, 4, 3, 2, 1 (one per line) and then Liftoff!.

איך הפלט אמור להיראות?What should the output look like?
5
4
3
2
1
Liftoff!
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1: int n = 5; while (n > 0) { ... n--; }int n = 5; while (n > 0) { ... n--; }
רמזHint 2: בלי n-- הלולאה לא תיגמר!Without n-- the loop never ends!
לפתרוןSolution
תרגילExercise 4

לוח הכפל של 7The 7 times table

הדפיסו 5 שורות: 7 x 1 = 7 עד 7 x 5 = 35.

Print 5 lines: 7 x 1 = 7 to 7 x 5 = 35.

איך הפלט אמור להיראות?What should the output look like?
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1: System.out.println("7 x " + i + " = " + (7 * i));System.out.println("7 x " + i + " = " + (7 * i));
לפתרוןSolution
תרגילExercise 5

סופרים תנועותCounting vowels

כמה תנועות (a, e, i, o, u) יש במילה "programming"? עברו על התווים עם for-each והדפיסו Vowels: 3.

How many vowels (a, e, i, o, u) are in "programming"? Go over the characters with for-each and print Vowels: 3.

איך הפלט אמור להיראות?What should the output look like?
Vowels: 3
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1: for (char c : word.toCharArray())for (char c : word.toCharArray())
רמזHint 2: if ("aeiou".indexOf(c) >= 0) אומר ש-c הוא תנועה.if ("aeiou".indexOf(c) >= 0) means c is a vowel.
לפתרוןSolution
תרגילExercise 6

צייד באגים: חסר אחדBug hunter: one missing

התוכנית אמורה להדפיס את המספרים 1 עד 5, אבל מדפיסה רק עד 4. תקנו את ה-טעות של אחד (off-by-one).

The program should print 1 to 5, but stops at 4. Fix the off-by-one.

איך הפלט אמור להיראות?What should the output look like?
1
2
3
4
5
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1: מה קורה כש-i שווה 5? התנאי i < 5 הוא false.What happens when i is 5? i < 5 is false.
רמזHint 2: <= כולל את 5.<= includes 5.
לפתרוןSolution
תרגילExercise 7

מדף, צעד 5: רשימה ממוספרתShelf, step 5: a numbered list

פרויקט מלווהCompanion project

במחרוזת books יש שמות של 3 ספרים מופרדים ב-;: "Dune;Emma;Ulysses". עברו עליהם (books.split(";") נותן אותם אחד-אחד; מערכים נלמד במפגש 8) והדפיסו רשימה ממוספרת 1. Dune וכן הלאה, ובסוף 3 books.

books holds 3 titles separated by ;: "Dune;Emma;Ulysses". Go over them (books.split(";") hands them out one by one; arrays come in session 8) and print a numbered list 1. Dune and so on, then 3 books at the end.

איך הפלט אמור להיראות?What should the output look like?
1. Dune
2. Emma
3. Ulysses
3 books
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1: for (String title : books.split(";"))for (String title : books.split(";"))
רמזHint 2: מונה משלכם: int n = 0; לפני, ו-n++ בכל סיבוב.Your own counter: int n = 0; before, and n++ each round.
לפתרוןSolution

אתגרים לחזקיםChallenges for the brave

אתגרChallenge 1

FizzBuzzFizzBuzz

הדפיסו את 1 עד 15, אבל במקום מספר שמתחלק ב-3 כתבו Fizz, במקום מתחלק ב-5 Buzz, ובמקום מתחלק בשניהם FizzBuzz.

Print 1 to 15, but write Fizz for numbers divisible by 3, Buzz for divisible by 5, and FizzBuzz for both.

איך הפלט אמור להיראות?What should the output look like?
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1: בודקים קודם את שניהם: i % 15 == 0.Check both first: i % 15 == 0.
רמזHint 2: אחר כך % 3, אחר כך % 5, ואחרת המספר.Then % 3, then % 5, otherwise the number.
לפתרוןSolution
אתגרChallenge 2

משולש מספריםA number triangle

עם לולאות מקוננות הדפיסו 4 שורות: 1, 12, 123, 1234.

With nested loops print 4 lines: 1, 12, 123, 1234.

איך הפלט אמור להיראות?What should the output look like?
1
12
123
1234
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1: החיצונית בוחרת שורה (row מ-1 עד 4), הפנימית מדפיסה 1 עד row.The outer loop picks a row (row 1 to 4); the inner prints 1 to row.
רמזHint 2: אחרי הלולאה הפנימית: System.out.println();.After the inner loop: System.out.println();.
לפתרוןSolution

נבנה על ידיBuilt by Ariel Yohimovich