Lesson 2 - While
Todays lesson
More Conditionals -
ifandelsewhile,breakanddo-while
שאלת חימום
מצא את המקסימום בין 4 מספרים
public class Main {
public static void main(String[] args) {
int a = 1, b=71, c=3, d= 10, max;
max = (a >b) ? a : b;
max = Math.max(max, c); //same thing
max = (max >d) ? max : d;
System.out.println(max);
}
}71כמה ספרות וכמה אפסים
קלוט מספר n
הדפס מספר הספרות
הדפס מספר האפסים
זה if מקוצר

version 2
let num be a random number from -1000 until 9999 (including)
Note: it includes the min but not the max [min, max)
Rotate Square

יש לסובב את הקוביה
טבלת מעקב

Version 2 : n right or left shifts

קלוט מספר n:
אם הוא חיובי אז סובב n פעמים ימינה
אם הוא שלילי אז סובב n פעמים שמאלה
note
since while (n_shifts>0) checks for positive numbers and we do n_shifts = n_shifts-1; inside the while loop without n_shifts = n_shifts * -1 if we have a left shift we would need another while loop
Find Aprox. log2
מצא עבור קלט x את:
קודם כל בא נבין מה קורה כאן
אם הוא לא חזקה שלמה הדפס את חזקה שלמה ועוד .x
2nd run
To find the real answer we should use a Talyor series.
Find Parallel lines
מצא האם 2 ישרים:
מקבילים
מאונכים
או לזה זה ולא זה


Last updated
Was this helpful?