Lesson 2 - While

Todays lesson

  • More Conditionals - if and else

  • while , break and do-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

יש לסובב את הקוביה

טבלת מעקב

track-table

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 את:

log2x=answerlog_2x=answer

קודם כל בא נבין מה קורה כאן

23=222=82^3=2*2*2=8
log28=3log_28=3

אם הוא לא חזקה שלמה הדפס את חזקה שלמה ועוד .x

2nd run

To find the real answer we should use a Talyor series.

Find Parallel lines

מצא האם 2 ישרים:

  • מקבילים

  • מאונכים

  • או לזה זה ולא זה

img source

Find The Slope Of A Line That Passess Through 2 Points - YouTube

img source

Last updated

Was this helpful?