Variables, types, strings, conditions, loops and input
60 דקותminutes4 שאלות בחירהmultiple choice3 שאלות קודcoding questions100 נקודותpoints
60:00השעון רק עוזר להתאמן. אפשר גם בלי.The timer is just for practice. You can skip it.
חלק א: שאלות בחירה (5 נקודות לשאלה)Part A: multiple choice (5 points each)
התשובות מתגלות רק כשמסיימים את המבחן.Answers are revealed only when you finish the exam.
חלק ב: שאלות קודPart B: coding questions
שאלהQuestion 5
ציון באותיותA letter grade
כתבו static String letter(int score): 90 ומעלה A, 80–89 B, 70–79 C, אחרת F. ציון מחוץ לטווח 0–100 מחזיר ?.
Write static String letter(int score): 90 and up A, 80–89 B, 70–79 C, otherwise F. A score outside 0–100 returns ?.
איך הפלט אמור להיראות?What should the output look like?
A B F ?
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:בדקו קודם את הטווח.Check the range first.
הפתרון שלנוOur solution
Main.java
publicclass Main {
staticString letter(int score) {
if (score <0|| score >100) {
return"?";
}
if (score >=90) {
return"A";
}
if (score >=80) {
return"B";
}
if (score >=70) {
return"C";
}
return"F";
}
publicstaticvoidmain(String[] args) {
System.out.println(letter(95) +" "+ letter(80) +" "+ letter(12) +" "+ letter(101));
}
}
פלטOutput
A B F ?
יש יותר מדרך נכונה אחת. אם הבדיקות עוברות, גם הפתרון שלכם נכון.There is more than one right way. If the checks pass, your solution is right too.
מחווןRubric (25 נקודותpoints)
כשכל הבדיקות עוברות, כל השורות מסומנות. אם לא, סמנו בעצמכם מה כן עשיתם נכון.When every check passes, all rows are ticked. If not, tick what you did get right.
שאלהQuestion 6
ראשי תיבותInitials
כתבו static String initials(String fullName) שמחזירה ראשי תיבות באותיות גדולות עם נקודות: "ada lovelace" → "A.L.". רווחים כפולים לא יוצרים נקודה ריקה, ומחרוזת ריקה מחזירה "".
Write static String initials(String fullName) returning capital initials with dots: "ada lovelace" → "A.L.". Double spaces don't create an empty dot, and an empty string returns "".
איך הפלט אמור להיראות?What should the output look like?
A.L. J.G.
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:fullName.trim().split("\\s+"), ודלגו על מילה ריקה.fullName.trim().split("\\s+"), and skip an empty word.
הפתרון שלנוOur solution
Main.java
publicclass Main {
staticString initials(String fullName) {
StringBuilder sb =newStringBuilder();
for (String word : fullName.trim().split("\\s+")) {
if (!word.isEmpty()) {
sb.append(Character.toUpperCase(word.charAt(0))).append('.');
}
}
return sb.toString();
}
publicstaticvoidmain(String[] args) {
System.out.println(initials("ada lovelace") +" "+ initials(" james gosling "));
}
}
פלטOutput
A.L. J.G.
יש יותר מדרך נכונה אחת. אם הבדיקות עוברות, גם הפתרון שלכם נכון.There is more than one right way. If the checks pass, your solution is right too.
מחווןRubric (25 נקודותpoints)
כשכל הבדיקות עוברות, כל השורות מסומנות. אם לא, סמנו בעצמכם מה כן עשיתם נכון.When every check passes, all rows are ticked. If not, tick what you did get right.
שאלהQuestion 7
חלוקת חשבוןSplitting a bill
קלט עם Scanner: שורה ראשונה סכום החשבון, שנייה מספר הסועדים, שלישית אחוז טיפ. הדפיסו Each pays: X עם שתי ספרות אחרי הנקודה. אם מספר הסועדים 0 או פחות, הדפיסו Need at least one person.
Input with a Scanner: the first line is the bill, the second the number of diners, the third a tip percent. Print Each pays: X with two decimals. If the number of diners is 0 or less, print Need at least one person.
איך הפלט אמור להיראות?What should the output look like?
100
3
15
Each pays: 38.33
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.
import java.util.Scanner;
publicclass Main {
publicstaticvoidmain(String[] args) {
Scanner sc =newScanner(System.in);
double bill = sc.nextDouble();
int people = sc.nextInt();
double tip = sc.nextDouble();
if (people <=0) {
System.out.println("Need at least one person");
} else {
double total = bill * (1+ tip /100);
System.out.printf("Each pays: %.2f%n", total / people);
}
}
}
פלטOutput
100
3
15
Each pays: 38.33
יש יותר מדרך נכונה אחת. אם הבדיקות עוברות, גם הפתרון שלכם נכון.There is more than one right way. If the checks pass, your solution is right too.
מחווןRubric (30 נקודותpoints)
כשכל הבדיקות עוברות, כל השורות מסומנות. אם לא, סמנו בעצמכם מה כן עשיתם נכון.When every check passes, all rows are ticked. If not, tick what you did get right.