class class_name
{
public static void main(String args[])
{
جملة الأوامر
}
}
· جملة الطباعة System.out.print();
· ترك سطر بعد الطباعة System.out.println();
· لترك مسافة كبيرةTab System.out.println(“\t”);
· لترك سطر قبل الطباعة System.out.print(“\n”);
· تعريف المتغيرات
Type var_name1, var_name2
int x,y
أمثلة :
- أكتب برنامج بلغة java يقوم بطباعة رسالة ترحيب على الشاشة..
class run
{
public static void main(String args[])
{
System.out.print(“Hello User”);
}
}
- أكتب برنامج يقوم بجمع العددين 5 , 10 ثم يطبع الناتج على الشاشة ..
class run
{
public static void main(String args[])
{
int x = 5, y = 10;
int z = x + y;
System.out.print(“Sum = ”+ z );
}
}
o كما يمكننا وضع العملية الحسابية داخل جملة الطباعة "لتوفير مساحة في الذاكرة" كما يلي :
class run
{
public static void main(String args[])
{
int x = 5, y = 10;
System.out.print(“Sum = ”+ (x + y) );
}
}
o ويمكننا أيضاً حساب الناتج دون الحاجة لحجز مخزن للمتغير كما يلي :
class sum
{
public static void main(String args[])
{
System.out.print(“Total = ”+ (5+10));
}
}
- ما هي مخرجات البرامج التالية..
- class ex
{
public static void main(String args[])
{
int x,y;
x = 10;
y = x++; // الزيادة بعد المساواة //
System.out.println( “x = “ + x + “\t y = “+ y);
x = 10;
y = ++x;// الزيادة قبل المساواة //
System.out.println( “x = “ + x + “\t y = “+ y);
}
}
المخرجات هي :
x = 11 y = 10
x = 11 y = 11
- class xy
{
public static void main(String args[])
{
int x,y;
x = 10;
y = x--; // الطرح بعد المساواة //
System.out.println( “x = “ + x + “\t y = “+ y);
x = 10;
y = --x;// الطرح قبل المساواة //
System.out.println( “x = “ + x + “\t y = “+ y);
}
}
المخرجات هي :
x = 9 y = 10
x = 9 y = 9
- class run_ex
{
public static void main(String args[])
{
int x,y,z,a;
x = 1;
y = 2;
z = -1;
a = x--;
z+ = y;
y = ++z;
x* = y;
System.out.println( “x = “ + x + “\t y = “+ y+”\t z = “+ z+ “\t a = “+ a);
}
}
المخرجات هي :
x = 0 y = 2 z = 2 a = 1
- class runex
{
public static void main(String args[])
{
int x,y,z,a;
x = 1;
y = 0;
z = -1;
a = ++x;
z = x+y;
y = z--;
x+ = y;
System.out.println( “x = “ + x + “\t y = “+ y+”\t z = “+ z+ “\t a = “+ a);
}
}
المخرجات هي :
x = 4 y = 2 z = 1 a = 2







said:



من بريطانيا العظمى المملكة المتحدة