Introduction To Java Programming CH2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

Introduction To Java Programming

Chapter 2

2.2. Writing Simple Programs


‫ "! إزاي        وآن ه ف ازاي  ا‬# ‫ ه‬$‫ د‬#&‫(' ا‬
.‫  *) اد‬+ ‫ ﺕ‬-). /0‫ و‬1‫  ا‬

‫ ؟؟‬algorithm /)‫  ف ) ' ا‬3)4)5 $6‫ول آ‬8‫(' ا‬

1" ‫ر‬0‫ول ﺕ‬8‫ ا‬/+"5  # ' )  ‫ (ة اي‬+"=# -)> ‫ ه‬algorithm ‫اـ‬
.‫ ﺕده‬1? ‫@ اة‬1A‫ك ﺕ‬65+‫  ه‬1> $‫ك ود‬A C‫ل ازاي (' و‬D‫واوض )ن ﺵ‬

 ‫' ه‬-1) ‫ة اوض  ا =" اة‬G‫ * دا‬H=+    3)4)5  I
:$6‫ زي آ‬C*

./"M6+‫ ه ا"' ه‬user‫ ا او ال‬/"M6‫ ﺱاء ه‬.-‫ ا‬P0 ‫ي‬-‫ اول ه‬-١

‫ ط‬:'  '‫ ا"' ه‬area= radius * radius * pi :‫ ا د‬3 ‫ة‬G‫ا‬6‫ * ا‬H= ‫ ه‬-٢
..-‫ ا‬P0 $‫ ه د‬radius ‫ واـ‬٢S

.*‫ ا‬U1.‫ ه‬-٣

6- #‫ام  ا(ر ﺕ‬6? 3 algorithm "5‫ ا‬C#= ‫  دي (ة  ﺱ" و‬1>
.‫ اد‬H# '-1 3)6 ‫ ا= و‬-)> '( ‫ول‬8‫ ا   ا‬3*8‫ا‬

(Y‫ ا‬.‫ت‬+1‫ ا‬+I‫ وﺕ‬+"=# -)> ‫ ودي‬Data Structures 6)6C W".0 '"5  ( +‫و‬
‫ ودول اﺱ! اـ‬int, float, double‫ت زي ال‬+1‫ ا‬+I# ‫ ع‬3 #‫ اآ‬+( 6 5
/+(‫ و‬array & string ‫ زي اـ‬objects ‫ اـ‬3 ‫ ااع‬$‫ د‬/+(‫ و‬Primitive data types
.(Y‫ (' ا‬3)4‫ه‬C 3+  ‫ ودول‬stack & linked lists ‫ زي اـ‬+‫ت ﺕ‬C*

‫'؟؟؟‬- $‫ د‬1‫أ  ازاي   ا‬61 ‫' ه‬#?‫ا د‬6C ‫ا‬6C +C

/+ ‫  ه‬5# ‫ آس (س‬/+( ‫زم )ن‬8 (C  ‫(  ان اي‬5  *‫ ا‬$6‫ول آ‬8‫ا‬
.ComputeArea
public class ComputeArea {
// Data and methods to be given later
}

: main method ‫زم   اـ‬8 ‫ ان‬3+(‫ر‬5 $‫ود‬


public class ComputeArea {
public static void main(String[] args) {
// Step 1: Read in radius

// Step 2: Compute area

// Step 3: Display the area


}
}

 ‫ وه‬1‫ ا‬3 ‫"ب‬.‫'   ا‬- ^( ‫د‬I+ 3+‫"  اس وا‬5  *‫' ا‬#?‫ د‬H+>
.1‫" (' ا‬5‫ات ا"' اوض ا‬._ comment  "5

‫ ؟‬user ‫ اـ‬3 .-‫ي ` ا‬-‫ ازاي ه‬8‫• او‬


‫ ازاي؟‬$   ‫ ازاي واﺕ‬/4_‫ ه‬+‫• ﺙ‬

user‫ ال‬3 M6#‫ ا"' ه‬+-‫ ا‬/+( ‫ن‬4_ ‫ ه‬+D# ‫ ا  ه ف‬S)> 35 ‫ه = ﺕ' &" اول‬
.-‫ ا‬P0 ‫ن‬4M‫ة ا‬4)5 ‫ ) ' ا‬1‫ (' ا‬8‫ د‬/ !‫ )ن اﺱ‬/‫ ا‬b) +D#‫واﺱ! ا‬
*‫ ا‬+? /+( ‫ن‬4M‫ ا‬+D#  ( *‫ ا‬+? U1.‫ ا' ه‬$‫ واوض د‬radius /+(
. area /+‫وه‬
public class ComputeArea {
public static void main(String[] args) {
double radius;
double area;

// Step 1: Read in radius

// Step 2: Compute area

// Step 3: Display the area


}
}
.  1> ‫! آر‬+( ! double ‫ ع‬3 !#(5‫و‬

‫ ؟‬.-‫ ا‬P0 +? ‫ي‬-‫ وه' ازاي ه‬6 5 c‫' ول &" آ‬Y+

: "M6) '"‫ ه ا‬user‫' _"' ال‬-1 ‫ ه‬$6‫ آ‬6 ‫ و‬#‫ ﺙ‬+?  *‫" ا‬M6 ‫أ) ه‬61  *‫ا‬
‫ ا د‬5 $6‫ آ‬6 ‫ و‬٢٠ ‫ ـ‬.-‫ ا‬P0 +? M‫ول د‬8‫ ا‬/+? ‫ ه‬$‫ د‬1‫  =" ا‬+C 
51.‫" ا‬C $6‫ آ‬6 ‫ و‬radius * radius ‫ ه‬+"M  e radius2 35  ^ #‫" واﺱ‬.‫ا‬
+?  1> 3)6 ‫" و‬The area for the circle of radius" '‫د) وه‬5 "C ‫ول‬8‫  ا‬1>
1‫ ا‬3 ' C‫ ا"' را‬+-‫ه وا‬1‫" ا"' ا آﺕ‬Y‫ ا‬3+ @‫  (' ا‬6_#‫ واﺱ‬.-‫ ا‬P0
‫ د‬+"5 '( ‫د) او‬5 UC +"5 '( ‫ إ‬3+#* '( 6_#  ‫ دي‬UY‫ ا‬5‫( و‬+) ‫ــ‬
P0 +? 3+‫ و‬#1#‫" ا"' ا آ‬Y‫ ا‬3+ ‫ د‬$6‫ آ‬6 5 ‫ زي‬f  H C String 3 #‫اآ‬
"‫ آ‬3+ '‫ ﺕ‬3)6 )‫" و‬is" "‫ وآ‬.-‫ ا‬P0 +? 3+ @‫ ار‬c+C  '‫ ﺕ‬/#6_#‫ واﺱ‬.-‫ا‬
$ (5 '"‫ ا‬51.‫ام ا ا‬6_#‫ﺱ‬e $‫ ا د‬c 1> M‫ ا* و(' ا‬+? 3+‫" و‬is"
. System.out.println

:‫ وه‬3+ G‫ ﺵ‬3)g.M $‫  د‬-+‫و‬

‫ و(' ا= دي‬/+( ‫( (' ان ا"' اوض ﺕن‬+)‫ ال‬.=# H## c‫ وا‬3 -١
:‫ زي‬error U".+‫ه‬
System.out.println("Introduction to Java Programming,
by Y. Daniel Liang"+);
:$6‫)  زي آ‬6 ‫ ﺕ‬S)> 35 $‫ د‬error‫   ال‬3‫و‬
System.out.println("Introduction to Java Programming, " +
"by Y. Daniel Liang");
Liang");

2.3.. Identifiers
‫ات واـ‬+D#‫ ه *) اﺱ' ا‬H+> !‫ اﺱ‬/ #M‫ ا‬.-‫ ا‬P0 ‫ع‬# +D#‫"  ا‬5  +C 
‫؟؟؟‬U ‫ ﺕ‬C* ‫ اي‬8‫ و‬65‫ا‬- = ‫ دي‬methods

: ‫زم‬8 +D#‫ وه' ان اﺱ! ا‬65‫ا‬- = ‫ل ا‬- ‫ه‬

. public, void, main, static ‫ زي‬l=‫ ا"ت ا‬3 "‫ آ‬+-١

. ($), (_) ‫ آن زي‬M ‫ *وف و*وف‬5Y ‫ )ن اي‬3 -٢

.Y  +( 0=+ +* +"5 ‫أ ?! او )ن‬61) +D#‫   اﺱ! ا‬+ -٣

. true , false or null ‫   )ن‬+ -٤

./> "&  ‫ )ن اي >ل‬3 -٥

$2 ComputeArea,
$2, area radius,, and : =+= ‫دس‬I+‫ات و‬+D# '‫"' اﺱ‬5 "I‫ا‬
ComputeArea area,
. showMes
showMessageDialog
sageDialog

2A and d+4 : @"j ‫دس‬I+‫ات و‬+D# '‫"' اﺱ‬5 "I‫ا‬

‫ وال‬#‫ ا=وف ا‬3+ ‫ق‬# ' ) case sensitive (Y‫  إن ا‬: A*  -+
. x /‫ ا"' اﺱ‬+D#‫ ا‬+j X /‫ ا"' اﺱ‬+D#‫( ?' ان ا‬

)‫"&ن ﺕ ?ا‬5 1‫  ' (' ا‬/ !‫ر اﺱ‬#M‫ ا‬+D# '‫' ﺕ‬Y+‫  ﺕ‬: =+0  -+‫و‬
. $ ‫ ـ‬+D# '‫ ﺕ‬k‫ ا‬b) 8 $‫ ود‬.‫ك‬+j '"5‫ و‬k '"5 ‫اد‬
2.4.. Variables
‫ات‬+D#‫ل ا‬-+ 3&+‫ ان ا‬5

!   +  ‫ت‬+ ‫ن‬4_) /‫ ا‬/  ‫ف‬6‫ آن ا‬.-‫ ا‬P0  +D#  "5   *‫ ا‬+C H+>
U  ‫ات آ" (' اي‬+D#‫ ا‬+l‫ت اه' ه' دي و‬+1 o#= /‫ ازاي ا! ا‬/"#"‫و‬
.  
  ‫ ة‬3 #‫ اآ‬+-‫ ا‬/")‫ اد‬3 +D#‫ا "! ان ا‬

: ‫ل‬I
// Compute the first area
radius = 1.0;
1.0 area = radius * radius * 3.14159;
System.out.println("The area is " + area + " for radius " + radius);
System.out.println("The

// Compute the second area


radius = 2.0;
2.0
area = radius * radius * 3.14159;
3.14159
System.out.println("The area is " + area + " for radius " + radius);
System.out.println("The

‫ ؟؟‬+D# ‫ ازاي‬5‫ ا‬H+>

:'‫ وه‬+D# ‫ اي‬# ‫ة‬65? /+(


datatype variableName;

(;)‫" ــ‬Y‫ و ' ا‬/‫ اﺱ‬3)6 ‫ و‬+D#‫اول  ف ع ا‬

: ‫ات‬+D# '‫"' اﺱ‬5 "I‫ا‬


int x; // Declare x to be an integer variable;
double radius; // Declare radius to be a double variable;
double interestRate; // Declare interestRate to be a double variable;
char a; // Declare a to be a character variable;

'( 6*‫ آ وا‬5‫زم ا‬8  ‫  ا ع‬3 +D# 3 #‫ ا'    اآ‬$‫   " د‬-+‫و‬
: $6‫ زي آ‬6*‫ وا‬.‫ (' ﺱ‬f  U ! C‫ ا‬3 $6* .‫ﺱ‬
int i, j, k; // Declare i, j, and k as int variables
lower case ‫أ =ف ﺱل‬61# ‫ات‬+D#‫ ان اﺱ' ا‬/+"5 ‫ رف‬#‫ ان ا‬$‫ د‬A*  -+
interestRate ‫ زي‬# ‫ي‬6#1‫ ﺕ‬+#‫' ا" ا‬-1) 3+#"‫ آ‬3 ‫و‬

2.5 Assignment Statements and Assignment Expressions


2.5.

‫(  ان‬5 '-1) +C H+> +? .-‫ ا‬P0  ‫ي‬6  +C  (=) 5  6_#‫  ا*  اﺱ‬1>
: $‫"' ام د‬5 "I‫ وا‬+D#‫ (' ا‬+-‫=@ ا‬# ‫وي‬#‫ ا‬5
int x = 1;
; // Assign 1 to variable x;
x
double radius = 1.0;
; // Assign 1.0 to variable radius
radius;
x = 5 * (3 / 2) + 3 * 2; // Assign
Assign the value of the expression to x;
x = y + 1;
; // Assign the addition of y and 1 to x;
area = radius * radius * 3.14159 // Compute area
3.14159;

: '‫ ﺕ‬+D# '( ‫ او‬+D#‫ ﺕ' ('  ا‬/.=‫ و‬+"5 '( +D#‫م ا‬6_# ‫ آن‬3
x = x + 1;

١ ‫" دي ـ‬Y‫ ا‬1? x ‫ ) '  آن‬x '( '‫ ﺕ‬/#+.*‫ و‬6*‫ وا‬x '"5 c C ‫" دي‬Y‫(' ا‬
. ٢ ‫ه ـ‬6  '-1+‫ه‬

' ) 3++‫"' ا‬5 +-‫"' ا&ل وا‬5 /‫ن اﺱ‬+ ‫ ان‬+D#‫ ا‬#‫ة ا  (' آ‬65-‫ ان ا‬o*‫و‬
.@"j '-1+‫ ه‬1= =x : $6‫ آ‬/#1#‫ آ‬

6‫ة اﺕآ‬4)5  6_#‫ اﺱ‬3 ‫ دي آن‬+D# '( +? @=#   ‫وي‬#‫ ا‬5 ‫وآن‬
: $6‫ ) ' زي آ‬+D# '(  +  +? 3
System.out.println(x = 1);
: ‫ دي‬Y‫  ا‬U ‫وي‬## ‫ودي‬
x = 1;
System.out.println(x);
: W 1# ) $6‫ آ‬c1#‫  آ‬$‫ود‬
‫;‪i = j = k = 1‬‬
‫ودي ‪##‬وي ‪: U‬‬
‫;‪k = 1‬‬
‫;‪j = k‬‬
‫;‪i = j‬‬

‫‪ A*  -+‬آ) ‪6C‬ا  ‪ '"5 +D# c(5‬ا‪   + int /‬ا*@ (‪ +( +? /+‬آ ‪&5‬ي‬
‫ن ‪65 /5‬د =‪ $6( W+‬ه‪ 3  @"j '-1+‬ا‪ casting 5‬وا‪ 1-) /+"M‬ا‪ +-‬دي و‪3‬‬
‫د‪^ $‬ع ‪ /‬ه‪&#+‬ح ?‪6‬ام ﺵ)‪.‬‬

‫و‪6 3‬ل   ف ا‪ '( +D#‬ﺱ‪ .‬و‪ /")6‬ا‪ '( +-‬ﺱ‪ .‬ا‪ /+"M‬آ"‪ '( /‬ﺱ‪ .‬وا*‪ 6‬زي‬
‫آ‪: $6‬‬
‫;‪int x = 1‬‬

‫ودي و) ‪ '" @1A‬آن  "‪ 1? /‬آ‪: $6‬‬


‫;‪int x‬‬
‫;‪x = 1‬‬

‫و‪ A*  -+‬ﺕ‪   + +‬ا*@ ?‪ +j 3 +D# '( +‬ا‪5‬ف ‪ /5‬ا‪8‬ول او ا‪/"5‬‬
‫‪. declaration‬‬

‫‪2.6. Constants‬‬
‫>‪ H+‬د?‪ '#‬ا ‪ +D# c"5‬وا ‪5‬رف ان ?‪ 3 /#+‬ﺕ‪> +D#‬ل ا‪  H+> 1‬ا ‪4)5‬‬
‫ا‪ /#+? +D# 5‬ﺙ‪4)5  /#‬ه ﺕ‪> +D#‬ل ا‪ 3 1‬ا‪5‬ف ‪ '"5 +D#‬ا‪ /‬ﺙ‪ c‬زي‬
‫آ‪: $6‬‬
‫;‪final datatype CONSTANTNAME = VALUE‬‬

‫وا   ا‪ +D#‬ا‪ cI‬د‪8 $‬زم ا‪ /(5‬واد)"‪ '( +? /‬ا‪8‬ول وآ" ‪ final‬دي آ" =‪l‬‬
‫ ه ان ا‪ +D#‬د‪ /#+? $‬ﺙ‪ #‬و ه‪> +D##‬ل ا‪.1‬‬
: /‫ا‬6_#‫"' اﺱ‬5 ‫ل‬I‫و‬
// ComputeArea.java: Compute the area of a circle
public class ComputeArea {
/** Main method
me */
public static void main(String[] args) {
final double PI = 3.14159;
; // Declare a constant

// Assign a radius
double radius = 20;
20
// Compute area
double area = radius * radius * PI;
;

// Display results
System.out.println("The area for the circle of radius " +
System.out.println("The
radius + " is " + area);
}
}

. Pi ‫ او‬pi  PI ‫ زي‬#‫' آ‬-1+ cI‫ ا‬+D#‫ ان اﺱ! ا‬/+"5 ‫ رف‬#‫ ا‬A*  -+

: '‫ب وه‬1‫ت اﺱ‬# ‫ا‬6C 6+ #I‫ات ا‬+D#‫ام ا‬6_#‫ اﺱ‬/‫   " وه' ا‬-+

. 1‫ (' ا‬/#+? +D‫ج آ ﺵ) ﺕ‬#=  -١

. 6*‫ة (' ن وا‬6*‫ ة وا‬.= +-‫ ا‬-٢

. ‫ ?ا) اد‬+"5 '"+‫ ه‬+D#" H‫ر اﺱ!  ﺱ‬#M‫ ا' ا‬-٣

2.7 Numeric Data Types and Operations


2.7.

‫ ! ؟؟‬+ ‫ اق‬/)‫ ا‬H+> int, double ‫" زي‬#_ ‫ ااع‬3 ‫ات‬+D#  (5  *‫' ا‬#?‫د‬

‫ ع‬3 +D# ‫اآة  ع ) ' اول   ف‬q‫ ا‬3 4Y=## '"‫اق اﺱﺱ' ه ا* ا‬
..‫ا‬q‫ وه‬double ‫ ع‬3 +D#‫ ا‬+j * ‫اآة‬q‫ (' ا‬/+ 4Y=#+ I int
‫ا‪ ٨ +( (Y‬ااع ‪ 3‬ا‪+D#‬ات ود‪6C $‬ول (‪ /+‬ا ع وا* ا"' ‪ / 4Y=##‬و‪I#) 3‬‬
‫(' آم ‪bit‬‬

‫وا‪ ٣ +( (Y‬ااع ‪ 3‬ا‪+D#‬ات  ‪ 4)5‬ﺕ ف ‪65‬د =‪ W+‬وه ‪byte, short, int & :‬‬
‫‪long‬‬

‫و ‪ 4)5‬ﺕ ف ‪65‬د ‪&5‬ي او ‪ /‬آر (‪ float & double : 3+5 /+‬و‪-+‬ل ان ‪3‬‬
‫ا*‪ 3‬اﺱ‪6_#‬ام اـ ‪ / double‬ادق ‪ 3‬اـ ‪. float‬‬

‫‪2.7.1.‬‬
‫‪2.7.1 Numeric Operators‬‬

‫ا&‪ 3‬د‪5 35 !"#+ $‬ت ا "‪+‬ت ا=‪ +‬زي ا"' (' ا‪6Y‬ول د‪: $‬‬
‫‪-+‬ل د‪ "  $‬ان ﺕ ? ‪65‬د)‪ 3+=+= 3‬ه‪65 U".+‬د =‪ W+‬د‪ $‬و‪4C‬ء ا‬
‫ه‪q=#+‬ف ) ' ‪ 5/2 I‬ه‪2.5  2 U".#‬‬

‫د‪ 5 $‬اـ ‪ %‬ودي ‪ '? H+Y#‬ا‪ !- 'Y+   ' ) -‬ر?‪ -). 3+‬دي ا"' ‪'"5‬‬
‫ا&ل ‪ '-1+‬اﺱ‪ dividend /‬وا"' ‪ '"5‬ا‪ '-1+ 3++‬اﺱ‪7 % 3  ?  I divisor /‬‬
‫ه‪#‬ن ا ‪ ' ) 1 Y+#‬ﺕ ا‪ -‬ا د) ‪ ٢‬وه‪ ١ '-1#+‬اه ه د‪ $‬ا ﺕ‪.‬‬

‫و ‪  "5‬ا "‪ +‬دي ‪ '"5‬ار?م ﺱ‪ 1‬ا ﺕ ‪ U".+‬ﺱ‪  @-( H‬ا"' ‪ '"5‬ا&ل ﺱ‪. H‬‬

‫>‪ )*  1‬ا‪ '?1‬دي ‪6+‬ة ‪6C‬ا ‪6C‬ا (' ا‪ U".+     I ' ) Y1‬ا‪65‬اد‬
‫ا‪4‬و‪ +C‬او اد) ‪ 3‬ا‪5‬ف ار?م  ‪t‬ن ا?! ا‪4‬و‪ ٢ '"5 /#? '? 'C‬دا) ـ‪0‬‬
‫وادي ?' ?‪ /#‬دا) ـ ‪1‬‬

‫و‪I H)C‬ل ‪ '"5‬ا=) دي ‪-+‬ل  ا*  اردة ا‪ c1‬وا‪ c‬وا=‪ k‬ه‪"-##‬ا آن ‪١٠‬‬
‫ا)م و‪ 4)5‬ا‪5‬ف ه‪) '-1+‬م ا)‪ /‬؟؟  ا?‪6‬ر ا*‪6‬د ا‪+‬م  د دي‪:‬‬
/‫ اة ا‬3+ ‫ﺙ‬t‫' )م ا‬-1+ !‫ه‬6 5 ‫ع (' اورو ) ' اول )م‬1‫م اﺱ‬A '"5 '‫ ﺵ‬$‫  د‬1>
'? ‫ب‬C‫ و‬f  '"5 ! C ‫ ?م‬+C ‫ ا)م‬١٠ 6  ‫م ادس و دي‬+‫' (' ا‬#?‫?ل ا د‬
‫ع ا"' ه )م‬1‫ اﺱ‬3 '#‫م ا‬+‫' (' ا‬-1+‫ ) ' ا د ه‬٢ U"> /"‫ع آ‬1‫"' اﺱ‬5 !#?
. ‫ﺙء‬I‫ا‬

./"M6 ‫ ا‬34‫ ا‬3 +‫ا' (' آ‬I‫ وا‬SG?6‫د ا‬65 H=+  ‫ل‬I ‫ آن‬$‫ود‬
1 import javax.swing.JOptionPane;
2
3 public class DisplayTime {
4 public static void main(String[] args) {
5 int seconds = 500;
6 int minutes = seconds / 60;
7 int remainingSeconds = seconds % 60;
8 JOptionPane showMessageDialog(nul
JOptionPane.showMessageDialog
showMessageDialog null,
9 seconds + " seconds is " + minutes +
10 " minutes and " + remainingSeconds
11 + " seconds");
seconds"
12 }
13 }

SG?6‫د ا‬65 ‫ف‬5‫"&ن ا‬5 )‫ ا د‬- ٦٠ '"5 '"‫ا' ا‬I‫د ا‬65  ? $‫ د‬1‫ه  (' ا‬
.SG?6‫  ! ا‬c"+‫  ﺵ‬6  '‫ا‬I‫د ا‬65 ‫ف‬5‫"&ن ا‬5 '?1‫ ا‬S). !#? 3)6 ‫و‬

U".# 3‫ آ" و‬Y+# ‫ ا‬U".#  )&5 ‫اد‬65‫"' ا‬5 0=# +"5 ‫ ان اي‬A*  -+
.H)-‫ون اي ﺕ‬6 "‫ آ‬Y+# ‫ ا‬U".# =+=0‫اد ا‬65‫"' ا‬5 ‫ت‬+" ‫ (' ا‬3‫ و‬-

. ‫ن‬4_#‫ي وﺕ‬-## ‫! وازاي‬+-‫ م ا‬35 $6  '"‫ ا‬3&‫"! (' ا‬#+‫ ه‬$6‫ آ‬6 

2.7.3.
2.7.3 Arithmetic Expressions
‫ ؟؟؟؟‬H=#+ ‫  وازاي‬Y '( ‫ آ‬+1 ‫ ﺕ‬H# ‫ازاي‬

: $6‫ آ‬/"‫' ﺵ‬-1+‫ د ه‬$ *  $‫ل زي د‬I


(3 + 4 * x) / 5 – 10 * (y - 5)
) * (a + b + c) / x +
9 * (4
( / x + (9
( + x) / y)
+1 ‫ وه' ان اي ﺕ‬65‫ ?ا‬S1.+ /* 6 5‫ و‬/1# ‫ زي‬$‫ا‬- ‫دي زي‬5 3+)‫وزي *  ﺵ‬
UY‫ت ا‬+"5 ) ‫ و(' ا‬3++" ‫ ا&ل‬3 -‫ب وا‬b‫ ا‬$6‫ آ‬6  ‫ اول‬H=#+ ‫ ا?اس‬3+
.3++" ‫ ا&ل‬3 $‫ح ود‬.‫وا‬

:'‫ ه‬/#‫و) و د‬4+"+" c)‫ اـ‬3 ‫ت ا=ارة‬C‫=ل در‬+  ‫ل‬I

Celsius = (Fahrenheit – 32)

: /‫ اه‬1‫وا‬
1 public class FahrenheitToCelsius {
2 public static void main(String[] args) {
3 double fahrenheit = 100;
100 // Say 100;
4 double celsius = (5.0 / 9) * (fahrenheit - 32);
5 System
System.out.println
println("Fahrenheit
"Fahrenheit " + fahrenheit + " is " +
6 celsius + " in Celsius");
Celsius"
7 }
8 }

‫د‬65  )&5 +-‫ ا ﺕ آ‬H+C‫"&ن ا‬5 (5.0 / 9)  ?  ‫ ا‬U‫ اا‬.‫ (' ا‬o* ‫وه‬
0 ‫' ا ﺕ‬-1+‫( آن ه‬5/9) ‫  آن ﺱ‬W+=

2.7.4.
2.7.4 Shorthand Operators

: ‫" زي دي‬C  "-‫ (' اد ﺕ‬3


i = i + 8;
i '( '‫ و=@ ا ﺕ ﺕ‬i +D#‫ ا‬+? '"5 ٨ UY  +(‫و‬
‫‪ 0#_ 3‬ا‪ "Y‬دي و‪6_#‬م ا‪ +1 #‬د‪: $‬‬
‫;‪i += 8‬‬
‫واﺱ‪ shorthand operator /‬و(‪ /+‬آن ز)‪  /‬ا "‪+‬ت زي آ‪:$6‬‬

‫و(‪ /+‬آن اﺕ ‪ 3+‬ز)دة  ‪ '( !6_#‬ز)دة ا‪ +D#‬ا*‪ 6‬او ﺕ ‪ /0+-‬د‪ +- $‬وا*‪ 6‬و?ا‪65‬ه‬
‫(' ا‪6Y‬ول د‪: $‬‬

‫اق ‪ 3+‬و‪C‬د ‪ 1? ++‬ا‪ +D#‬او  ‪ $6‬ه ان  ‪#‬ن ا  ?‪ 1‬ا‪ +D#‬د‪ $  $‬ان ?‪/#+‬‬
‫ه‪ 6)4#‬اول ا*‪ 6‬و ‪ 3)6‬ﺕ‪ !#‬ا "‪ +‬ا‪ '"5 ".‬ا‪ +-‬ا‪6)6Y‬ة ‪ ،‬ا  ا   ‪ 6‬ا‪+D#‬‬
‫د‪ $  $‬ان ا "‪ +‬ا‪ ".‬ه‪ /+"5 !##‬اول و ‪ /#+? 3)6‬ه‪ 6)4#‬ا*‪ 6‬وآ‪I‬ل "‪: W+^#‬‬

‫ه  ا "‪ +‬ﺕ‪ c‬ا‪8‬ول وه' ا‪^ /‬ب اـ ‪ ١٠ '( i‬و ‪ 3)6‬زود ‪ '"5‬اـ ‪ i‬وا*‪ 6‬وه‪+‬ن اـ‬
‫‪newNum = 100‬‬
‫‪ 3‬ه  زود اول اـ‪ i‬ا*‪ 6‬و ‪  ^ 3)6‬ا‪ +-‬ا‪6)6Y‬ة (' ‪ ١٠‬وه‪+‬ن اـ = ‪newNum‬‬
‫‪110‬‬

‫‪-+‬ل ‪ =+0‬وه' ‪65‬م ا‪t‬آ‪I‬ر ‪ 3‬اﺱ‪6_#‬ام ا‪ -).‬دي (' آ‪ #‬ا‪+1 #‬ات  ‪4#‬ود ‪3‬‬
‫  اد‪.‬‬

‫‪2.8. Numeric Type Conversions‬‬

‫ا*‪#=  +‬ج ا  ‪ !b‬اآ‪ 3 #‬ع ‪ '( +D#‬ﺕ ‪ +1‬وا*‪ 6‬زي آ‪:$6‬‬


‫;‪byte i = 100‬‬
‫‪100‬‬
‫;‪long k = i * 3 + 4‬‬
‫;‪double d = i * 3.1 + k / 2‬‬

‫‪?  -+‬ا‪ "  5 65‬اي ﺕ ‪ /+( +1‬اآ‪ 3 #‬ع ‪ 3‬ا‪+D#‬ات‪:‬‬

‫ آن (‪ 3 +D# /+‬ع ‪ double‬إذن آ ا‪+D#‬ات )‪=#‬ل ‪ !5‬إ' ‪. double‬‬ ‫‪-‬‬
‫   (‪ 3 +D# /+‬ع ‪ float‬إذن آ ا‪+D#‬ات )‪=#‬ل ‪ 5‬إ' ‪. float‬‬ ‫‪-‬‬
‫   (‪ 3 +D# /+‬ع ‪ long‬إذن آ ا‪+D#‬ات )‪=#‬ل ‪ 5‬إ' ‪. long‬‬ ‫‪-‬‬
‫  )‪ '-1‬ا‪+D#‬ات آ" ﺕ‪ 3 '-1‬ع ‪. int‬‬ ‫‪-‬‬

‫) ' ‪ 1/2 6 5  I‬ه‪ '-1+‬ا ﺕ ‪ 0‬ن ا?‪  3 int 3+‬آن‪ 1.0/2‬ه‪ '-1+‬ا ﺕ ‪ 0.5‬ن‬
‫(‪ /+‬ر?!  ! ‪=##( double‬ل ال‪ ٢‬ا' ‪ double‬و‪ 6 5‬ﺕﺕ‪ H+‬ااع ‪:‬‬
‫ ا  )   زي‬3 int /+"M‫ وا‬float ‫ ع‬3 +D# +? ‫ ادي‬3 ‫ ا‬$   ' )
: $6‫آ‬
float f = (float
float)10.1
10.1;
int i = (int
int)f;
.+-‫ ا‬3 ‫&ل‬#+‫ء ا &ي ه‬4Y‫و(' ا= دي ا‬

'‫' ا‬5‫ ارا‬+D# ‫' ا*ل ع‬C‫ ) '  ا‬casting 5‫' ا‬C‫  ش  ا‬A* ‫ل‬-+‫و‬
error U".+‫ ا  ه‬3 ?‫"'  ع ا‬5‫ ع ا‬3 ‫=ل‬

‫ ه‬/= '"‫ ا‬+D#‫ ع ا‬+D+  casting‫ ال‬-). )=#‫ ان ا‬A* ‫ل آن‬-+
. /+( ‫ ا"' =ل‬+1 #‫  (' ا‬/#+? +D+

:3+)&5 3+? HG‫ا‬b‫ ا‬+? H=+  ‫ دي وه‬+G4Y‫"' ا‬5 S+1.#‫  آ‬5‫و‬
1 public class SalesTax {
2 public static void main(String[] args) {
3 double purchaseAmount = 197.55;
4 double tax = purchaseAmount * 0.06;
0.06
5 System
System.out.pri
println((int
int)(tax * 100)
100 / 100.0);
100.0
6 }
7 }

purchaseAmount ‫ ه‬HG‫ا‬b‫" ا‬1=‫ ا"' ه‬+-‫ ا‬/+( ‫ ا"' اوض‬+D#‫ ه  ا‬6 5‫و‬
'‫ وه‬1 '( y"1‫ ا‬+? ‫ب‬b+ /e HG‫ا‬b‫ ا‬H=+ $‫ ود‬tax +D#‫ وا‬197.55 /#+?‫و‬
U">‫وز ا‬5 ‫  ا‬11.853 $‫ د‬A  U".‫ اوض ﺕ‬HG‫ا‬b‫ ا‬+? U1>‫ ا‬c+C ‫ و‬0.06
"C _‫ ا‬.‫ (  (' ا‬casting‫ ال‬-)> ‫م‬6_#‫  (ﺱ‬3+)&5 3+?‫ ر‬6  Y+# ‫ا‬
' ) 100.0 '"5 ‫ ?م ?ﺱ‬1185 c ".( 100 '( HG‫ا‬b‫ ا‬+? ‫  ﺕ ^ب‬casting
11.85 '‫ وه‬double +? M‫ ا ﺕ (' ا‬U".( double +?

2.9 Character Data Type and Operations


2.9.
‫ *ف‬+I# ‫م‬6_#+ /‫  ا‬-+‫ و‬char ‫ات وه اـ‬+D#‫ ا‬3 ‫"' ع‬5 ‫ ف‬#  $‫ د‬3&‫(' ا‬
: /+"5 ‫ل‬I‫' و‬-'
' 3+ /#+? ‫ن‬#‫@ و‬-( 6*‫وا‬
char letter = 'A';
char numChar = '4';
٤ !?‫' *@ ا‬#‫ل ا‬I‫ و(' ا‬letter /‫ ا"' اﺱ‬+D#‫ (' ا‬A ‫ل اول *@ ا=ف‬I‫(' ا‬
. numChar +D#‫ آ=ف (' ا‬3‫و‬

 single quote 3+ ‫زم ﺕن‬8 char ‫ ع‬3 +D#‫ (' ا‬.= '"‫ ا‬+-‫ ا‬: A*
'A' 3‫ و‬string /5 "A" ' ) char c+‫ و‬string '-1#‫ ه‬double quote 3+ #+.*
. char /5

2.9.1. Unicode and ASCII Code

‫ اد‬3 3+5 6 5 ‫ ا=وف‬3)4_‫ا) وﺕ‬-‫ي ازاي و‬-#+ ‫ (  ا=ف‬+ $‫ د‬3&‫(' ا‬


'
'\u0000' ‫ اول‬3 ‫ن آد ا=وف‬+‫ و‬unicode‫! ال‬56# (Y‫ وا‬unicode & ASCII:
uFFFF' 6=
'\uFFFF'

:‫ و?ا) ا=وف‬#‫ آ‬-)> '"5 ‫ل‬I $‫ ود‬hexadecimal‫ ل‬# ‫ن ا=وف‬#‫و‬

:‫ وه‬char ‫ ع‬3 +D# '( +? !+ M‫ اد‬3 3+#-)> 6 5 '#?‫) ' د‬
char letter = 'A';
char letter = '\u0041
0041'; // Character A'
A's
s Unicode is 0041
char‫"' ال‬5 S1.‫ ﺕ‬3 increment & decrement
decrement `+- #‫ وا‬6)‫و‬4#‫ ا‬-)> : A*
:b‫ *ف ال‬U1.+‫ل ه‬I $‫ات ا د) ود‬+D#‫@ زي ا‬1A /)‫ز‬
char ch = 'a';
'a'
System.out.println(++ch);

2.9.2. Escape Sequences for Special Characters

‫ او‬tab‫ام اـ‬6_#‫ﺱ‬e ‫ر‬.‫ ا‬3 3+  ‫د‬65 6  3‫ ا ﺕ و‬U1>‫ ا' ا‬4)5 '-1 ‫ل‬D‫ وا ﺵ‬+*‫ا‬
‫ "م دي‬M ‫ *وف‬c"5 ‫ ا‬S)> 35 ‫ دي‬+_‫( ا‬# (Y‫ ا‬، .‫ ﺱ‬H+‫ا' اﺱ‬
:$6‫ول آ‬6Y‫?   )\( زي ا"' (' ا‬1 ‫ن‬#

:‫" دي‬Y‫ ا‬U1.‫ ﺕ‬4)5 k‫ ا‬I ‫ا(ض‬


He said "Java is fun"
:$6‫ه " آ‬
System.out.println("He said \"Java
System.out.println("He "Java is fun\"");
fun
2.9.3 Casting Between char and Numeric Types
2.9.3.

: ‫ ه‬I ' ) "& ‫ اي‬+ '‫ ي ع ﺕ‬char‫ ع ال‬3 +D#‫ر =ل ا‬6-  1>
char c = (char
char)0XAB0041
0041; // the lower 16 bits hex code 0041 is
// assigned to c
System.out.println(c); // c is character A
‫ء ا‬4Y‫ه ا‬Y‫! ﺕ‬#+ )&5 5 /+( ' ) float ‫ ا ع‬3 +D#‫ ا‬6 5 ‫و )ن‬
:$6‫ زي آ‬W+=0‫ء ا‬4Y‫=ل  ا‬#+‫و‬
char c = (char
char)65.25;
; // decimal 65 is assigned to t
System.out.println(c); // c is character A
:I $6‫ ي ع ﺕ' زي آ‬char 3 ‫' ا*ل‬C‫و ا=)  ا‬
int i = (int
int)'A';
; // the Unicode of character A is assigned to
i
System.out.println(i); // i is 65

‫ي ار?م او‬M‫! ا‬+-‫  آن ا‬k‫=ل ?! اوﺕﺕ‬## char ‫ ع‬3 +? )=‫ ﺕ‬6 5 :A*
‫ زي‬#‫ د  اآ‬0=+ ' ) '‫ زي ه‬/+"5 ‫ف‬b # string U ‫دة‬C ‫*وف و‬
:$‫ل د‬I‫ا‬
int i = '2' + '3'; // (int)'2'
( ' is 50 and (int)'3
3' is 51
System.out.println("i is " + i);
System.out.println("i

int j = 2 + 'a'; // (int)'a'


( is 97
System.out.println("j is " + j);
System.out.println("j
System.out.println(j + " is the Unicode for character " + (
(char)j);
)j);

System.out.println("Chapter" + '2');
System.out.println("Chapter"

display

i is 101
j is 99
99 is the Unicode for character c
Chapter 2
2.10 The String Type
2.10.

'-1) k?‫" = ا‬C ‫ن‬4M‫ ا‬4)5 ‫  ا‬H+> ، ‫ *ف‬+&) ‫ر‬6-) +D#  (5 '#?‫ا*  د‬
: $6‫ زي آ‬string ‫ ع‬3  +D# ‫م‬6_#‫هﺕ‬
String message = "Welcome to Java";
Java"

' ) JOptionPane‫ زي ال‬/)‫ ز‬class‫ ط ب‬/ ‫اع‬8‫  زي آ ا‬string ‫ ال‬3‫و‬


primitive ‫ش‬1# ) ' ) int, double‫ة زي ال‬4‫ه‬Y‫ ااع ا‬3 ‫ش‬1# ) string ‫ال‬
‫' ه‬#?‫ام ا"' )  د‬6? W^+‫ ه‬$‫  ' ام د‬reference type 1# ) ‫ ه‬3‫ و‬type
‫ ودي‬f  Ustring 3+ ‫ او اد اﺕ‬+? /+( @*‫ وازاي ا‬string ‫ ع‬3 +D# 5‫ازاي ا‬
: /+"5 "I‫ا‬
// Three strings are concatenated
String message = "Welcome" + "to" + "Java";
"Java"

// String Chapter is concatenated with number 2


String s = "Chapter" + 2; // s becomes Chapter2
Chapter

// String Supplement is concatenated with character B


String s1
s = "Supplement" + 'B';
'B' // s becomes SupplementB
"Welcome +? /+( String 6 5  ' ) += $‫ر د‬0#Mt‫ آد ا‬$  ‫م‬6_#‫ اﺱ‬3 ‫وآن‬
:$6‫ آ‬c?  message I /‫ واﺱ‬to java"
message += " and Java is fun";
fun";
"Welcome to Java and Java is fun" :$6‫ن ا ﺕ آ‬+‫ه‬

???‫" دي‬Y‫ ﺕ ا‬/)‫' ا‬-1+‫ ه‬j=2


j= ‫ و‬i=1 6 5  ‫ل‬I ‫ل‬-+
System.out.println("i +
System.out.println("i j is " + i + j);
' ) 12 '‫ ا"' ه‬j +? $6‫ آ‬6 ‫ و‬i +? U1.+‫ ه‬$6‫ آ‬6 ‫" و‬i+j is " U1.+‫ ه‬/‫ ا‬0=+‫ا"' ه‬
: ‫' ا ﺕ‬-1+‫ه‬
i + j is 12

:$6‫ ا?اس زي آ‬3+ !.=‫' ه‬-1) j ‫ و‬i 3+ UY‫ ا‬+? U1>‫ ا‬4)5 ‫و‬
System.out.println("i +
System.out.println("i j is " +( i + j));
2.11. Getting Input from Input Dialogs

1‫ ا‬3 .-‫ ا‬P0 +? M6   ‫ة آ‬G‫ا‬6‫ ('  * ا‬H+> $6‫ آ‬6= ‫ ?ي‬+C
‫ اﺱ‬-)> /+( H+> ‫ل (' اد‬65‫ وا‬1" '‫ ﺕ‬M6‫ ه‬+-‫ ا‬+j‫ ا' ا‬c+1*  H+>
‫د‬I+‫ (' ا‬JOptionPane ‫د (' ال‬C $‫ ود‬input dialogue 3 +-‫ ا‬M‫وه' ا' اد‬
. showInputDialog ‫ا"' اﺱ‬

: $‫ء د‬4Y‫' ا‬-1+‫ل  ه‬6 #+‫ء ا"' ه‬4Y‫ ا‬$6‫ آ‬1? $ 1#‫دي زي آ‬5 1‫ ا‬H# ‫ه‬

M6) user‫_"' ال‬#‫" ا"' ه‬Y‫ ا‬3)6 ‫ (' وﺱ@ ا&ﺵ و‬U".‫_"' اﺱ ﺕ‬# null "C ‫اول‬
$6‫ آ‬6 ‫ و‬dialog‫ ان ال‬5 $6‫ آ‬6 ‫" و‬Enter an input" +-‫ا‬
. ‫م‬#‫ﺱ‬t‫ ا‬5 A  ‫"&ن ) ض‬5 JOptionPane.QUESTION_MESSAGE
JOptionPane.QUESTION_MESSAGE
2.11.1. Converng Strings to Numbers

H+> !?‫ *ف  ر‬/‫"' ا‬5 ‫ي‬-#+‫ ر?! ه‬M‫  اوض ا' اد‬$‫('  زي ا"' (ت د‬
6 5  ' ) !? *‫" دي وا‬M6 '"‫ ا‬+-‫ ا‬6M‫ ؟؟؟ ا= ا' ا‬/)‫ا= "&" دي ا‬
: $6‫' آ‬-1+‫ ه‬int !? /*‫ة ا‬4)5‫ و‬intString /‫ اﺱ‬string
stri
int intValue = Integer.parseInt(intString);
:$6‫' آ‬-1+‫ ه‬double +? /+( 3‫ و‬string +D# ‫ ا*ل‬4)5 ‫و‬
double doubleValue = Double.parseDouble(doubleString);

.‫"' آ ا"' (ت‬5 S+1.#‫ آ‬case study ‫ آـ‬3+Y /+( $6‫ آ‬6 ‫و‬

2.13 Getting Input from the Console


2.13.

!+-‫ ا‬M‫وز ا' اد‬5  ‫ ﺵ'  ا‬JOptionPane‫ ال‬-). +?  "M‫' ا*  د‬#?‫ د‬H+>
‫' ازاي؟؟؟؟‬-1+‫ ه‬command prompt ‫ ال‬3

‫دس‬I+‫ ا‬3 5C '"5 ‫ي‬#=+ Scanner /‫ اﺱ‬6)6C ‫م   آس‬6-# jdk 1.5 _ ‫(' ا‬
: $6‫ ف زي آ‬#+‫ات و‬+D#‫ ا‬3 ‫ اي ع‬user‫ ال‬3 1-#‫ ا' اﺱ‬3 ' # '"‫ا‬
System.out.print
System.out.print("Enter
"Enter a double value: ");
"
Scanner scanner = new Scanner(System.in);
double d = scanner.nextDouble();

H+‫" وﺕ‬Y‫ ا‬U1.# println ‫ اق ان‬3‫ و‬println ‫@ زي‬1A '‫ ه‬print ‫د‬I+ : A*
. /b  H C /"‫ آ‬U1.# print 3 .‫ه ﺱ‬6 

: Scanner ‫ام آس‬6_#‫"' ا‬5 ‫ل‬I


1 import java.util.Scanner; // Scanner is in java.util
2
3 public class TestScanner {
4 public static void main(String
main(String args[]) {
5 // Create a Scanner
6 Scanner scanner = new Scanner(System.in);
7
8 // Prompt the user to enter an integer
9 System
System.out.print
print("Enter
"Enter an integer: ");
"
10 int intValue = scanner.nextInt();
scanner.nextInt()
11 System
System.out.println
println("You
"You entered the integer " + intValue);
12
13 // Prompt the user to enter a double value
14 System
System.out.print
print("Enter
"Enter a double value: ");
"
15 double doubleValue = scanner.nextDouble();
scanner.nextDouble()
16 System
System.out.println
println("You
"You entered the double value "
17 + doubleValue);
18
19 // Prompt the user to enter a string
20 System
System.out.print
print("Enter
"Enter a string without space: ");
");
21 String string = scanner.next();
scanner.next
22 System
System.out.println
println("You
"You entered the string " + string);
23 }
24 }
: $6‫' آ‬-1+‫وﺵ ا_ج ه‬

2.14.. Programming Style and Documentation


‫ ﺵ‬U".+ /"‫   آ‬1+ /"‫' ه ا& ) ' آ‬#‫ ا‬35  ‫ق‬+ '"‫اوض ان ا‬
65# ‫ت‬C* ‫ت آ دي‬-+" #‫ ا‬U)‫ ﺕز‬3* ، ‫م‬A  ‫ب‬# ‫ اد وه‬A  +C /Y
. +C 1‫ا ﺕ_"' ﺵ ا‬

H* '"5 ‫ و ء اد )ن‬S+‫ت )ن & ا‬-+" #‫ ا‬U)‫ ﺕز‬I ‫ زي‬W)0 ‫ل‬-) ‫أ‬61+‫و‬
small "‫' اول آ‬-1‫ ﺕ‬3+#"‫ و آ‬small ‫ات ﺕن‬+D#‫ اﺱء ا‬I ' ) + ‫اات ا‬
‫ زي‬1‫ ا ﺱ‬3‫ (ت (' اآ‬H+  ‫=  ا‬0 + ‫ وآن‬capital +( ‫ اول *ف‬+#‫وا‬
: $6‫آ‬
:$6‫ زي آ‬/)‫ ا‬/#)‫ و‬/)‫ ا‬/#)‫ا‬6 ‫ آ ?س‬W^)‫! و‬A  ‫ )ن‬blocks‫وآن ﺵ ال‬

2.15.
2.15 Programming Errors

‫ او‬runtime errors
error ‫ او‬syntax errors
error ‫ء (' اد إ‬.M8‫ ا‬3 ‫ ﺕت ااع‬/+( 6 5
logical errors

: $6‫ زي آ‬D"‫ ا‬65‫"@ (' ?ا‬j '-1+ $‫ ود‬Syntax errors ‫ اول ع وه اـ‬-
// ShowSyntaxErrors.java: The program contains syntax errors
public class ShowSyntaxErrors {
public static void main(String[] args) {
i = 30;
System.out.println(i + 4);
);
}
}
‫ )ن‬W0‫ آن اوض ا‬/5 ‫ف‬5‫ ا‬+j 3 +? /"#)‫ اد‬i +D#‫ ان ا‬/+( '"‫"@ ا‬D‫ ا‬$‫ود‬
: $6‫آ‬
// ShowSyntaxErrors.java: The program contains syntax errors
public class ShowSyntaxErrors {
public static void main(String[] args) {
int i = 30;
System.out.println(i + 4);
}
}

‫ ن‬Y+# ‫ن‬+‫ و‬compilation‫ ال‬+"5 6  0=+ $‫ ود‬runtime errors ‫ ﺕ' ع وه‬-
: $6‫   ' زي آ‬+  '"5 -‫ ا‬I ‫ه زي‬q+ ‫ ﺕ‬+=#‫ ا‬3 +"5 /+(
// ShowRuntimeErrors.java: Program contains runtime errors
public class ShowRuntimeErrors {
public static void main(String[] args) {
int i = 1 / 0;
}
}

3‫ و‬+"‫ت ﺱ‬+" ‫ وا‬+"‫ ﺱ‬65‫ا‬-‫ن ا‬# $‫ و(' ا ع د‬logical errors‫ ع وه اـ‬c‫ ﺕ‬-
 $‫ د‬$6‫ زي آ‬/ 1‫ ا‬g.M ‫ن‬+ 1j $‫ د‬g._‫ وا‬/  ‫"ب‬.‫ ا‬q +  1‫ا‬
: 3+?‫ ر‬UY+ /‫اوض ا‬
// ShowLogicErrors.java: The program contains a logic error
public class ShowLogicErrors {
public static void main(String[] args) {
// Add number1 to number2
int number1 = 3;
int number2 = 3;
number2 += number1 + number2;
System.out.println("number2 is " + number2);
}
}

number2 +D#‫ ا‬+? +> ' ) !  6*‫ن ا ﺕ (' وا‬4M 3+?‫ ا‬UC 6  /‫"@ ه  ا‬D‫وا‬
.

`"M #&‫ )ن ا‬$6‫و‬

 +C  ‫ان * ﺕ‬4+ '( {‫ ا‬/" C‫ و‬/  6+#) ‫)رب ا‬

You might also like