Professional Documents
Culture Documents
שיעור חזרה 1 - פתרונות
שיעור חזרה 1 - פתרונות
1 שאלה
:Card המחלקה
// דרך ב
//return this.value == num;
}
// סעיף ב
if (c1.equalValue(c2.getValue())){
System.out.println("Yes");
}else {
System.out.println("No");
}
// סעיף ג
String newShape = null;
// דרך א
String[] shapesArray = new String[4];
shapesArray[0] = shape1;
shapesArray[1] = shape2;
shapesArray[2] = shape3;
shapesArray[3] = shape4;
// דרך ב
//Tiltan
if (!c1.getShape().equals(shape1) && !c2.getShape().equals(shape1)){
newShape = shape1;
}
//Lev
else if(!c1.getShape().equals(shape2) && !c2.getShape().equals(shape2)){
newShape = shape2;
}
//Yahalom
else if(!c1.getShape().equals(shape3) && !c2.getShape().equals(shape3)) {
newShape = shape3;
}
//Alim
else{
newShape = shape4;
}
// סעיף ד
System.out.println(c3.toString());
// סעיף ה
if (c1.equalValue(c3.getValue()) || c2.equalValue(c3.getValue())){
System.out.println("C3 has same value as C1 or C2");
}
}
}
2 שאלה
.א
public class Baby {
private String id;
private char gendfer;
private double height;
private double weight;
B2: ("2222",'F',70,2.8)
B3: ("3333",'M',70,3.5)
Output:
***
*!!*
ממדיים-מערכים חד
1 שאלה
int sum = 0;
for(int i = 0; i < arr.length; i++){
if (arr[i] >= 100 && arr[i] <= 450) {
sum += arr[i];
}
}
2 שאלה
int count = 0;
for(int i = 0; i < arr.length; i++){
if (arr[i] >= 10 && arr[i] < 100) {
count++;
}
}
3 שאלה
if (isValid){
System.out.println("yes");
}else {
System.out.println("no");
}
4 שאלה
// סעיף א
int countRandomNums = 0;
for(int i = 0; i < arr.length; i++){
if ((i % 2 == 0 && arr[i] != 99) ||
(i % 2 == 1 && arr[i] != 49)){
arr[i] = (int) (Math.random() * 7) + 7;
countRandomNums++;
}
}
// סעיף ב
// מערך חדש עבור המספרים הרנדומליים בלבד
int[] randomArr = new int[countRandomNums];
int randomArrIndex = 0;
// סעיף ג
for (int i = 0; i < randomArr.length; i++) {
System.out.println(randomArr[i]);
}
מחרוזות
1 שאלה