משתנים וטיפוסים פרימיטיבייםVariables & primitive types
int, double, boolean, char ו-long, var, המרות טיפוסים, גלישה (overflow) וחלוקה של מספרים שלמים.
int, double, boolean, char and long, var, type conversions, overflow and integer division.
בעוד שנהNext year
תזכורת: מה ביקשוReminder: the task
צרו משתנה name מסוג String ומשתנה age מסוג int. הדפיסו <שם> בן/בת <גיל>, אחר כך הוסיפו 1 לגיל בתוך המשתנה והדפיסו שוב את הגיל החדש.
Create a String variable name and an int variable age. Print <name> is <age>, then add 1 to the age inside the variable and print the new age.
סימולציה: הפתרון רץ שורה אחרי שורה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
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
הפתרון המלא והפלט שלוFull solution and its output
public class Main {
public static void main(String[] args) {
String name = "נועה";
int age = 15;
System.out.println(name + " בת " + age);
age = age + 1;
System.out.println("בשנה הבאה: " + age);
}
}public class Main {
public static void main(String[] args) {
String name = "Noa";
int age = 15;
System.out.println(name + " is " + age);
age = age + 1;
System.out.println("Next year: " + age);
}
}נועה בת 15 בשנה הבאה: 16
Noa is 15 Next year: 16
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
מחליפים קופסאותSwapping boxes
תזכורת: מה ביקשוReminder: the task
ב-a יש 5 וב-b יש 9. החליפו ביניהם בלי לכתוב את המספרים שוב, והדפיסו a = 9, b = 5. רמז: צריך קופסה שלישית.
a holds 5 and b holds 9. Swap them without writing the numbers again, then print a = 9, b = 5. Hint: you need a third box.
סימולציה: הפתרון רץ שורה אחרי שורה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
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
הפתרון המלא והפלט שלוFull solution and its output
public class Main {
public static void main(String[] args) {
int a = 5;
int b = 9;
int temp = a;
a = b;
b = temp;
System.out.println("a = " + a + ", b = " + b);
}
}a = 9, b = 5
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
ממוצע ציוניםGrade average
תזכורת: מה ביקשוReminder: the task
שלושה ציונים: 85, 90 ו-78. שמרו כל אחד במשתנה int, חשבו את הממוצע במשתנה double והדפיסו אותו עם שתי ספרות אחרי הנקודה: 84.33.
Three grades: 85, 90 and 78. Keep each in an int variable, compute the average in a double variable and print it with two digits after the point: 84.33.
סימולציה: הפתרון רץ שורה אחרי שורה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
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
הפתרון המלא והפלט שלוFull solution and its output
public class Main {
public static void main(String[] args) {
int g1 = 85;
int g2 = 90;
int g3 = 78;
double avg = (g1 + g2 + g3) / 3.0;
System.out.printf("%.2f%n", avg);
}
}84.33
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
מצלזיוס לפרנהייטCelsius to Fahrenheit
תזכורת: מה ביקשוReminder: the task
במשתנה double celsius שימו 30. חשבו fahrenheit = celsius * 9 / 5 + 32 והדפיסו 30.0C = 86.0F.
Put 30 in a double celsius variable. Compute fahrenheit = celsius * 9 / 5 + 32 and print 30.0C = 86.0F.
סימולציה: הפתרון רץ שורה אחרי שורה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
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
הפתרון המלא והפלט שלוFull solution and its output
public class Main {
public static void main(String[] args) {
double celsius = 30;
double fahrenheit = celsius * 9 / 5 + 32;
System.out.println(celsius + "C = " + fahrenheit + "F");
}
}30.0C = 86.0F
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
צייד באגים: הממוצע שנעלםBug hunter: the vanishing half
תזכורת: מה ביקשוReminder: the task
הקוד אמור להדפיס 7.5, אבל מדפיס 7.0. אין שגיאה: זה באג לוגי. מצאו ותקנו.
The code should print 7.5 but prints 7.0. There's no error: it's a logic bug. Find it and fix it.
סימולציה: הפתרון רץ שורה אחרי שורה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
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
הפתרון המלא והפלט שלוFull solution and its output
public class Main {
public static void main(String[] args) {
int a = 7;
int b = 8;
double avg = (a + b) / 2.0;
System.out.println(avg);
}
}7.5
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
מדף, צעד 2: ספר במשתניםShelf, step 2: a book in variables
תזכורת: מה ביקשוReminder: the task
שמרו ספר אחד במשתנים: String title, String author, int year, double rating ו-boolean read. הדפיסו כרטיס של 4 שורות: שם וסופר, שנה, Rating: 4.5/5, ו-Read: true.
Keep one book in variables: String title, String author, int year, double rating and boolean read. Print a 4-line card: title and author, year, Rating: 4.5/5, and Read: true.
סימולציה: הפתרון רץ שורה אחרי שורה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
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
הפתרון המלא והפלט שלוFull solution and its output
public class Main {
public static void main(String[] args) {
String title = "הנסיך הקטן";
String author = "Antoine de Saint-Exupéry";
int year = 1943;
double rating = 4.5;
boolean read = true;
System.out.println(title + " - " + author);
System.out.println("Year: " + year);
System.out.println("Rating: " + rating + "/5");
System.out.println("Read: " + read);
}
}public class Main {
public static void main(String[] args) {
String title = "The Little Prince";
String author = "Antoine de Saint-Exupéry";
int year = 1943;
double rating = 4.5;
boolean read = true;
System.out.println(title + " - " + author);
System.out.println("Year: " + year);
System.out.println("Rating: " + rating + "/5");
System.out.println("Read: " + read);
}
}הנסיך הקטן - Antoine de Saint-Exupéry Year: 1943 Rating: 4.5/5 Read: true
The Little Prince - Antoine de Saint-Exupéry Year: 1943 Rating: 4.5/5 Read: true
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
בלש הגלישהThe overflow detective
תזכורת: מה ביקשוReminder: the task
כמה שניות יש ב-100 שנה (365 ימים בשנה)? חשבו פעם אחת עם int ופעם עם long, והדפיסו את שתי התוצאות בשתי שורות. איזו נכונה? (הנכונה: 3153600000.)
How many seconds are in 100 years (365 days a year)? Compute it once with int and once with long, and print both results on two lines. Which is right? (The right one: 3153600000.)
סימולציה: הפתרון רץ שורה אחרי שורה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
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
הפתרון המלא והפלט שלוFull solution and its output
public class Main {
public static void main(String[] args) {
int wrong = 100 * 365 * 24 * 60 * 60;
long right = 100L * 365 * 24 * 60 * 60;
System.out.println(wrong);
System.out.println(right);
}
}-1141367296 3153600000
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
סכום הספרותSum of the digits
תזכורת: מה ביקשוReminder: the task
במשתנה n יש 4721. בלי לולאות, חשבו את סכום הספרות שלו (4+7+2+1) והדפיסו 14. השתמשו ב-% וב-/.
n holds 4721. Without loops, compute the sum of its digits (4+7+2+1) and print 14. Use % and /.
סימולציה: הפתרון רץ שורה אחרי שורה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
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
הפתרון המלא והפלט שלוFull solution and its output
public class Main {
public static void main(String[] args) {
int n = 4721;
int d1 = n % 10;
n = n / 10;
int d2 = n % 10;
n = n / 10;
int d3 = n % 10;
n = n / 10;
int d4 = n;
System.out.println(d1 + d2 + d3 + d4);
}
}14
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.