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

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

String ו-StringBuilderString & StringBuilder

מחרוזות הן עצמים שלא משתנים, מתודות שימושיות, השוואה עם equals, String.format ו-StringBuilder לבנייה יעילה.

Strings are immutable objects, useful methods, comparing with equals, String.format, and StringBuilder for efficient building.

נסו לפתור לבד לפני שמציצים. בנגן: חיצים במקלדת או הכפתורים. כל צעד מראה איפה (קובץ ושורה), מה כותבים ולמה.Try on your own before peeking. In the player use the arrow keys or the buttons. Each step shows where (file and line), what to write, and why.
תרגילExercise 1

שם באותיות גדולותName in capitals

תזכורת: מה ביקשוReminder: the task

במשתנים first ו-last שמרו שם פרטי ושם משפחה באנגלית. הדפיסו את השם המלא באותיות גדולות, ובשורה שנייה את מספר התווים שלו (כולל הרווח).

Keep a first and last name (in English) in first and last. Print the full name in capitals, and on a second line the number of characters in it (space included).

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy

סימולציה: הפתרון רץ שורה אחרי שורהSimulation: the solution runs line by line

לוחצים הבא או נגן: רואים איזו שורה Java מבצעת, מה יש בכל קופסה (משתנה) ומה מופיע על המסך. זו הרצה אמיתית של הפתרון.

Press Next or Play: see which line Java runs, what is in each box (variable) and what appears on the screen. This is a real run of the solution.

צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Java מבצעתLine by line, the way Java runs it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

הפתרון המלא והפלט שלוFull solution and its output
Main.java
public class Main {
    public static void main(String[] args) {
        String first = "Noa";
        String last = "Levi";
        String full = first + " " + last;
        System.out.println(full.toUpperCase());
        System.out.println(full.length());
    }
}
פלטOutput
NOA LEVI
8

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

תרגילExercise 2

ראשי תיבותInitials

תזכורת: מה ביקשוReminder: the task

במשתנה name יש "Noa Levi". הדפיסו את ראשי התיבות N.L. בעזרת charAt ו-indexOf (בלי לכתוב את האותיות בעצמכם).

name holds "Noa Levi". Print the initials N.L. using charAt and indexOf (without writing the letters yourself).

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy

סימולציה: הפתרון רץ שורה אחרי שורהSimulation: the solution runs line by line

לוחצים הבא או נגן: רואים איזו שורה Java מבצעת, מה יש בכל קופסה (משתנה) ומה מופיע על המסך. זו הרצה אמיתית של הפתרון.

Press Next or Play: see which line Java runs, what is in each box (variable) and what appears on the screen. This is a real run of the solution.

צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Java מבצעתLine by line, the way Java runs it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

הפתרון המלא והפלט שלוFull solution and its output
Main.java
public class Main {
    public static void main(String[] args) {
        String name = "Noa Levi";
        char first = name.charAt(0);
        int space = name.indexOf(" ");
        char second = name.charAt(space + 1);
        System.out.println("" + first + "." + second + ".");
    }
}
פלטOutput
N.L.

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

תרגילExercise 3

מחליפים מילהReplacing a word

תזכורת: מה ביקשוReminder: the task

במשתנה s יש "Java is hard". צרו משתנה חדש עם replace שבו hard הוחלף ב-fun, והדפיסו את שניהם: קודם את המקורי ואחר כך את החדש.

s holds "Java is hard". Make a new variable with replace where hard became fun, and print both: the original first, then the new one.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy

סימולציה: הפתרון רץ שורה אחרי שורהSimulation: the solution runs line by line

לוחצים הבא או נגן: רואים איזו שורה Java מבצעת, מה יש בכל קופסה (משתנה) ומה מופיע על המסך. זו הרצה אמיתית של הפתרון.

Press Next or Play: see which line Java runs, what is in each box (variable) and what appears on the screen. This is a real run of the solution.

צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Java מבצעתLine by line, the way Java runs it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

הפתרון המלא והפלט שלוFull solution and its output
Main.java
public class Main {
    public static void main(String[] args) {
        String s = "Java is hard";
        String t = s.replace("hard", "fun");
        System.out.println(s);
        System.out.println(t);
    }
}
פלטOutput
Java is hard
Java is fun

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

תרגילExercise 4

צייד באגים: false מוזרBug hunter: a strange false

תזכורת: מה ביקשוReminder: the task

הקוד משווה שתי מחרוזות עם אותו תוכן ומדפיס false. תקנו כך שיודפס true. (צפו בזיכרון בתזכורת למעלה כדי להבין למה.)

The code compares two strings with the same content and prints false. Fix it so it prints true. (Look at the memory view in the refresher above to see why.)

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy

סימולציה: הפתרון רץ שורה אחרי שורהSimulation: the solution runs line by line

לוחצים הבא או נגן: רואים איזו שורה Java מבצעת, מה יש בכל קופסה (משתנה) ומה מופיע על המסך. זו הרצה אמיתית של הפתרון.

Press Next or Play: see which line Java runs, what is in each box (variable) and what appears on the screen. This is a real run of the solution.

צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Java מבצעתLine by line, the way Java runs it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

הפתרון המלא והפלט שלוFull solution and its output
Main.java
public class Main {
    public static void main(String[] args) {
        String a = "java";
        String b = new String("java");
        System.out.println(a.equals(b));
    }
}
פלטOutput
true

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

תרגילExercise 5

קבלה מיושרתAn aligned receipt

תזכורת: מה ביקשוReminder: the task

הדפיסו קבלה עם printf: שלוש שורות של מוצר ומחיר (Coffee 12.5, Cake 18.9, Juice 25), שם המוצר ברוחב 8 וצמוד לשמאל, המחיר ברוחב 7 עם 2 ספרות. בשורה האחרונה Total והסכום (שימו את המחירים במשתנים ותנו ל-Java לחבר).

Print a receipt with printf: three product-and-price lines (Coffee 12.5, Cake 18.9, Juice 25), the name 8 wide and left-aligned, the price 7 wide with 2 digits. On the last line Total and the sum (keep the prices in variables and let Java add them up).

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy

סימולציה: הפתרון רץ שורה אחרי שורהSimulation: the solution runs line by line

לוחצים הבא או נגן: רואים איזו שורה Java מבצעת, מה יש בכל קופסה (משתנה) ומה מופיע על המסך. זו הרצה אמיתית של הפתרון.

Press Next or Play: see which line Java runs, what is in each box (variable) and what appears on the screen. This is a real run of the solution.

צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Java מבצעתLine by line, the way Java runs it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

הפתרון המלא והפלט שלוFull solution and its output
Main.java
public class Main {
    public static void main(String[] args) {
        double coffee = 12.5;
        double cake = 18.9;
        double juice = 25;
        System.out.printf("%-8s%7.2f%n", "Coffee", coffee);
        System.out.printf("%-8s%7.2f%n", "Cake", cake);
        System.out.printf("%-8s%7.2f%n", "Juice", juice);
        double total = coffee + cake + juice;
        System.out.printf("%-8s%7.2f%n", "Total", total);
    }
}
פלטOutput
Coffee    12.50
Cake      18.90
Juice     25.00
Total     56.40

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

תרגילExercise 6

פלינדרוםPalindrome

תזכורת: מה ביקשוReminder: the task

במשתנה word יש "level". הפכו אותו עם StringBuilder, הדפיסו את המילה ההפוכה, ובשורה שנייה true אם היא זהה למקור.

word holds "level". Reverse it with StringBuilder, print the reversed word, and on a second line true if it equals the original.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy

סימולציה: הפתרון רץ שורה אחרי שורהSimulation: the solution runs line by line

לוחצים הבא או נגן: רואים איזו שורה Java מבצעת, מה יש בכל קופסה (משתנה) ומה מופיע על המסך. זו הרצה אמיתית של הפתרון.

Press Next or Play: see which line Java runs, what is in each box (variable) and what appears on the screen. This is a real run of the solution.

צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Java מבצעתLine by line, the way Java runs it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

הפתרון המלא והפלט שלוFull solution and its output
Main.java
public class Main {
    public static void main(String[] args) {
        String word = "level";
        String back = new StringBuilder(word).reverse().toString();
        System.out.println(back);
        System.out.println(word.equals(back));
    }
}
פלטOutput
level
true

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

תרגילExercise 7

מדף, צעד 3: כרטיס מעוצבShelf, step 3: a formatted card

תזכורת: מה ביקשוReminder: the task

שמרו ספר במשתנים (title, author, year, stars מסוג int בין 1 ל-5). בנו עם String.format שורה בפורמט <title> | <author> | <year>, והדפיסו אותה ואחריה שורת כוכבים: * כפול stars (רמז: "*".repeat(stars)).

Keep a book in variables (title, author, year, stars as an int 1–5). Build with String.format a line like <title> | <author> | <year>, print it, and then a line of stars: * times stars (hint: "*".repeat(stars)).

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy

סימולציה: הפתרון רץ שורה אחרי שורהSimulation: the solution runs line by line

לוחצים הבא או נגן: רואים איזו שורה Java מבצעת, מה יש בכל קופסה (משתנה) ומה מופיע על המסך. זו הרצה אמיתית של הפתרון.

Press Next or Play: see which line Java runs, what is in each box (variable) and what appears on the screen. This is a real run of the solution.

צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Java מבצעתLine by line, the way Java runs it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

הפתרון המלא והפלט שלוFull solution and its output
Main.java
public class Main {
    public static void main(String[] args) {
        String title = "הנסיך הקטן";
        String author = "Saint-Exupéry";
        int year = 1943;
        int stars = 4;
        String card = String.format("%s | %s | %d", title, author, year);
        System.out.println(card);
        System.out.println("*".repeat(stars));
    }
}
public class Main {
    public static void main(String[] args) {
        String title = "The Little Prince";
        String author = "Saint-Exupéry";
        int year = 1943;
        int stars = 4;
        String card = String.format("%s | %s | %d", title, author, year);
        System.out.println(card);
        System.out.println("*".repeat(stars));
    }
}
פלטOutput
הנסיך הקטן | Saint-Exupéry | 1943
****
The Little Prince | Saint-Exupéry | 1943
****

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

אתגרChallenge 1

מפרקים אימיילTaking an email apart

תזכורת: מה ביקשוReminder: the task

במשתנה email יש "noa.levi@example.com". הדפיסו user: noa.levi ו-domain: example.com, ובשורה שלישית את שם המשתמש באותיות גדולות בלי הנקודה: NOALEVI.

email holds "noa.levi@example.com". Print user: noa.levi and domain: example.com, and on a third line the user name in capitals without the dot: NOALEVI.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy

סימולציה: הפתרון רץ שורה אחרי שורהSimulation: the solution runs line by line

לוחצים הבא או נגן: רואים איזו שורה Java מבצעת, מה יש בכל קופסה (משתנה) ומה מופיע על המסך. זו הרצה אמיתית של הפתרון.

Press Next or Play: see which line Java runs, what is in each box (variable) and what appears on the screen. This is a real run of the solution.

צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Java מבצעתLine by line, the way Java runs it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

הפתרון המלא והפלט שלוFull solution and its output
Main.java
public class Main {
    public static void main(String[] args) {
        String email = "noa.levi@example.com";
        int at = email.indexOf("@");
        String user = email.substring(0, at);
        String domain = email.substring(at + 1);
        System.out.println("user: " + user);
        System.out.println("domain: " + domain);
        System.out.println(user.replace(".", "").toUpperCase());
    }
}
פלטOutput
user: noa.levi
domain: example.com
NOALEVI

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

אתגרChallenge 2

כותרת יפהTitle case

תזכורת: מה ביקשוReminder: the task

במשתנה s יש "the little prince" (שלוש מילים). בלי לולאות, הדפיסו The Little Prince: האות הראשונה של כל מילה גדולה.

s holds "the little prince" (three words). Without loops, print The Little Prince: each word's first letter in capitals.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy

סימולציה: הפתרון רץ שורה אחרי שורהSimulation: the solution runs line by line

לוחצים הבא או נגן: רואים איזו שורה Java מבצעת, מה יש בכל קופסה (משתנה) ומה מופיע על המסך. זו הרצה אמיתית של הפתרון.

Press Next or Play: see which line Java runs, what is in each box (variable) and what appears on the screen. This is a real run of the solution.

צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Java מבצעתLine by line, the way Java runs it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

הפתרון המלא והפלט שלוFull solution and its output
Main.java
public class Main {
    public static void main(String[] args) {
        String s = "the little prince";
        int sp1 = s.indexOf(" ");
        int sp2 = s.indexOf(" ", sp1 + 1);
        String w1 = s.substring(0, sp1);
        String w2 = s.substring(sp1 + 1, sp2);
        String w3 = s.substring(sp2 + 1);
        String t1 = w1.substring(0, 1).toUpperCase() + w1.substring(1);
        String t2 = w2.substring(0, 1).toUpperCase() + w2.substring(1);
        String t3 = w3.substring(0, 1).toUpperCase() + w3.substring(1);
        System.out.println(t1 + " " + t2 + " " + t3);
    }
}
פלטOutput
The Little Prince

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

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