❓ ما ناتج الجمع مع break؟
What is the output with break?
What is the output with break?
int sum = 0;
for (int i = 1; i <= 5; i++) {
if (i == 4) break;
sum += i;
}
System.out.println(sum);
❓ do-while تُنفَّذ مرة على الأقل
do-while runs at least once
do-while runs at least once
int i = 5;
do { i++; } while (i < 5);
System.out.println(i);
❓ اقتران else بالأقرب
else pairs with nearest if
else pairs with nearest if
int x = 0, y = 10;
if (y > 0)
if (x == 1) System.out.print("A");
else System.out.print("B");
❓ switch مع break
switch with break
switch with break
int n = 1;
switch (n) {
case 1: System.out.print("X"); break;
default: System.out.print("Y");
}
❓ تمرير مصفوفة لميثود
Passing array to method
Passing array to method
static void inc(int[] a){
for (int i = 0; i < a.length; i++) a[i]++;
}
int[] a = {0,1,2};
inc(a);
System.out.println(a[2]);❓ اختيار overload مع null
Overload resolution with null
Overload resolution with null
void f(Object o){ System.out.print("O"); }
void f(String s){ System.out.print("S"); }
f(null);❓ حقول مقابل دالة مُعاد تعريفها
Fields vs overridden method
Fields vs overridden method
class A { int v = 1; int get(){ return v; } }
class B extends A { int v = 2; int get(){ return v; } }
A a = new B();
System.out.println(a.v + "," + a.get());❓ نسخ المصفوفة copyOf
Arrays.copyOf clone
Arrays.copyOf clone
int[] x = {1,2};
int[] y = java.util.Arrays.copyOf(x, x.length);
y[0] = 9;
System.out.println(x[0]);