דוגמה לפתרון שאלה 1 אם שורה מספר 1 הייתה:
int x=7, y=4, w=10;
מספר שורה |
x |
y |
w |
if(x%2==0) |
if(y%2==1) |
if(w%2==0) |
פלט |
1 |
7 |
4 |
10 |
||||
2 |
7 |
4 |
10 |
False |
|||
4 |
7 |
4 |
10 |
7 is not amazing |
|||
5 |
7 |
4 |
10 |
False |
|||
7 |
7 |
4 |
10 |
4 is amazing number |
|||
8 |
7 |
4 |
10 |
True |
|||
9 |
7 |
4 |
10 |
10 is amazing number |
שאלה 1
א. עקבו בעזרת טבלת מעקב (בעזרת דף ולא במחשב!) אחר התוכנית הבאה:
public class Main
{
public static void main(String[] args) {
int x=5, y=6, w=10;
if(x%2==0)
{
System.out.println(x+ " is amazing number");
}
else
{
System.out.println(x+" is not amazing number");
}
if(y%2==1)
{
System.out.println(y+" is not amazing number");
}
else
{
System.out.println(y+" is amazing number");
}
if(w%2==0)
{
System.out.println(w+" is amazing number");
}
else
{
System.out.println(w+" is not amazing number"); }
}
}
ב. מה התנאי בודק?
ג. על פי הגדרת השאלה: מספר מדהים הוא מספר ______ (השלימו)
שאלה 2
א') עקבו בעזרת טבלת מעקב (בעזרת דף ולא במחשב!) אחר התוכנית הבאה: בצעו 2 טבלאות מעקב כאשר הקלטים הם:
33
36
55
521
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int x, y;
System.out.println("please enter first int
number:");
x= input.nextInt();
System.out.println("please enter second int
number:");
y= input.nextInt();
if(x>y)
System.out.println("the ____ number between "+x+ " and "+ y+ " is:"+x);
else
System.out.println("the ____ number between "+x+ " and "+ y+ " is:"+y);
}
}
ב. מה התנאי בודק?
ג. מה התכנית מבצעת?
ד. השלימו את החסר בשורות
The _____ number between….
שאלה 3
א'.עקבו בעזרת טבלת מעקב (בעזרת דף ולא במחשב!*) אחר התוכנית הבאה: בצעו 2 טבלאות מעקב כאשר הקלטים הם:
90
-5
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int x;
System.out.println("please enter int number:"); x= input.nextInt();
if(x>=0)
System.out.println("the number is DIDI");
else
System.out.println("the number is GIGI");
}
}
ב. מה התוכנית מבצעת?
ג.על פי הגדרת התכנית, מספר המוגדר כ- "DIDI "הוא בהכרח: __________ על פי הגדרת התכנתי, מספר שמוגדר כ-"GIGI "הוא בהכרח: ___________
שאלה 4
א' עקבו בעזרת טבלת מעקב (בעזרת דף ולא במחשב!) אחר התוכנית הבאה: בצעו 2 טבלאות מעקב כאשר הקלטים הם (קליטת המספרים היא משמאל לימין):
0 1 2
3 1 2
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int x,y,z;
System.out.println("please enter int number:"); z= input.nextInt();
System.out.println("please enter first int number:");
x= input.nextInt();
System.out.println("please enter second int number:");
y= input.nextInt();
if(z==0)
System.out.println(x+"+"+y+"="+(x+y));
else if(z==1)
System.out.println(x+"-"+y+"="+(x-y));
else if(z==2)
System.out.println(x+"*"+y+"="+(x*y));
else if(z==3)
System.out.println(x+"/"+y+"="+(x/y));
}
}
ב. מה התוכנית יודעת לבצע?