for loops
This weeks lesson will cover:
breakandcontinueforloopsnested loops
⭐ - is difficulty of question
for loops
for loopsSimple for examples ⭐
for examples ⭐הדפס מספרים 0 עד 3
public class Main {
public static void main(String[] args) {
for (int i = 0; i < 4; i++) {
System.out.println(i);
} // end of for
}
}0
1
2
3?מה יודפס כאן
?מה יודפס כאן
?מה יודפס כאן
explanation
the keyword
continuewill continue to the next number in the loopthe keyword
breakwill exit the loop altogether.
Factorial and Sum of values ⭐⭐
חשב עצרת וסכום עבור n
example n=4
version 2
חשב את הערך של n עד שמקבלים -1
Question - Formula ⭐⭐
תקודדו את הנוסחה הבא:
הלוואה מבנק ⭐⭐
פלוני לקח הלוואה מהבנק ומחזיר 10 אחוז מהלוואה כל חודש הדפיסו
כמה כסף הוא מחזיר כל חודש
כמה הוא עדיין חייב אחרי 3 חודשים מאז שהוא התחיל לפרוע בחזרה
Catalan number ⭐⭐⭐
חשב את מספר קלטן n
for example
?מה זה מספר קלטן
זהו מספר האפשריות לניתן להגיע מפינה השמאלית למטה לפינה הימנית למעלה בלי לחצות את הקו וללכת רק ימינה ולמעלה
version 2
עכשיו תתדפיסו את כל המספרי קלטן עד n
Nested Loops
Print stars ⭐⭐
כתבו תוכנית אשר ידפיס משולש כוכבים עד גובה n
example:
code:
כתוב תוכנית אשר יציג את לוח הכפל (עד10)
1x1 = 1
2x1 = 2
3x1 = 3
4x1 = 4
5x1 = 5
6x1 = 6
7x1 = 7
8x1 = 8
1x2 = 2
2x2 = 4
3x2 = 3
4x2 = 8
5x2 = 10
6x2 = 12
7x2 = 14
8x2 = 16
1x10 = 10
2x10 = 20
3x10 = 30
4x10 = 40
5x10 = 50
6x10 = 60
7x10 = 70
8x10 = 80
Later on we will use more nested loops for accessing multi-dimension arrays
e^x ⭐⭐⭐⭐
compute e^x using the following formula:
example:
if accurray or n=12 we get
in the outer loop
each time we reset factorial to calculate the factorial
while the inner loop runs until n each time
version 2
display each accuracy until n
think how large 12! is its 479,001,600
Remember than e = 2.718281828459045 which isn't bad at all, each time we are accurate by one decimal
Graph ⭐⭐
תכתבו תוכנית אשר מקבלת 2 מספרים שלמים m וn
ומדפיסה בטרמינל את הישר שלהם על גרף בין 10 למינוס 10 בציר הx והציר הy

Last updated
Was this helpful?