Trace a Program Execution public class Compute Area i assign 20 to radius /* Main method * public static void main( Stringl args)( double radius. radius 20 double area area no value / Assign a radius adIts / Compute area area= radius radius 3.14159 / Display results System. out printIn("The area for the circle of radius"+ radius+"is"+ area) Liang, Introduction to Java Programming, revised by dai-kaiyt
Liang, Introduction to Java Programming,revised by Dai-kaiyu 6 Trace a Program Execution public class ComputeArea { /** Main method */ public static void main(String[] args) { double radius; double area; // Assign a radius radius = 20; // Compute area area = radius * radius * 3.14159; // Display results System.out.println("The area for the circle of radius " + radius + " is " + area); } } radius 20 area no value assign 20 to radius
Trace a Program Execution public class Compute Area i /* Main method * memory public static void main( Stringl args)( double radius. radius 20 double area area 1256.636 / Assign a radius radius= 20 / Compute area compute area and assign it to variable area area=radius radius *3. 14159 / Display results System. out printIn("The area for the circle of radius"+ radius+"is"+ area) Liang, Introduction to Java Programming, revised by dai-kaiyt
Liang, Introduction to Java Programming,revised by Dai-kaiyu 7 Trace a Program Execution public class ComputeArea { /** Main method */ public static void main(String[] args) { double radius; double area; // Assign a radius radius = 20; // Compute area area = radius * radius * 3.14159; // Display results System.out.println("The area for the circle of radius " + radius + " is " + area); } } radius 20 memory area 1256.636 compute area and assign it to variable area
Trace a Program Execution public class Compute Area i /* Main method * memory public static void main( Stringl args)( double radius. radius 20 double area area 1256.636 / Assign a radius radius= 20 / Compute area area= radius radius 3.14159 print a message to the le / Display results System. out. printIn("The area for the circle of radius radius+ A string constant should not cross Ines Liang, Introduction to Java Programming, revised by dai-kaiyu
Liang, Introduction to Java Programming,revised by Dai-kaiyu 8 Trace a Program Execution public class ComputeArea { /** Main method */ public static void main(String[] args) { double radius; double area; // Assign a radius radius = 20; // Compute area area = radius * radius * 3.14159; // Display results System.out.println("The area for the circle of radius " + radius + " is " + area); } } radius 20 memory area 1256.636 print a message to the console A string constant should not cross lines
Identifiers o An identifier is a sequence of characters that consist of letters, digits, underscores ( and dollar signs(s o An identifier must start with a letter, an underscore (,or a dollar sign (S). It cannot start with a digit O An identifier cannot be a reserved word o An identifier can be of any lengt o Are used for naming variables, constants, methods, classes and packages Liang, Introduction to Java Programming, revised by dai-kaiyu
Liang, Introduction to Java Programming,revised by Dai-kaiyu 9 Identifiers ⚫ An identifier is a sequence of characters that consist of letters, digits, underscores (_), and dollar signs ($). ⚫ An identifier must start with a letter, an underscore (_), or a dollar sign ($). It cannot start with a digit. An identifier cannot be a reserved word. ⚫ An identifier can be of any length. ⚫ Are used for naming variables, constants, methods, classes, and packages
Java Keywords abstract boolean bre ak byte case catch char class continue default double e⊥se extends false final finally float 士。卫 if implements import instanceof int interface long native new null package private protected public 卫 e turn sho卫t static super switch synchronized this throw throws transient true try void volatile wn⊥e Key woras that are ye served but not used by jaa Cons t goto Rg. 4.2 Ja va keywords. Liang, Introduction to Java Programming, revised by dai-kaiyt
Liang, Introduction to Java Programming,revised by Dai-kaiyu 10