tailieunhanh - Lecture Introduction to Java programming - Chapter 2: Elementary programming
In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical problems programmatically. Through these problems, you will learn Java primitive data types and related subjects, such as variables, constants, data types, operators, expressions, and input and output. | Chapter 2 Elementary Programming Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical problems programmatically. Through these problems, you will learn Java primitive data types and related subjects, such as variables, constants, data types, operators, expressions, and input and output. Objectives To write Java programs to perform simple calculations (§). To obtain input from the console using the Scanner class (§). To use identifiers to name variables, constants, methods, and classes (§). To use variables to store data (§§). To program with assignment statements and assignment expressions (§). To use constants to store permanent data (§). To declare Java primitive data types: byte, short, int, long, float, double, and char (§§). To use Java operators to write numeric expressions (§§–). To display current time (§). To use short hand operators (§). To cast value of one type to another type (§). To compute loan payment (§). To represent characters using the char type (§). To compute monetary changes (§). To represent a string using the String type (§). To become familiar with Java documentation, programming style, and naming conventions (§). To distinguish syntax errors, runtime errors, and logic errors and debug errors (§). (GUI) To obtain input using the JOptionPane input dialog boxes (§). Introducing Programming with an Example Listing Computing the Area of a Circle This program computes the area of the circle. ComputeArea Run IMPORTANT NOTE: To enable the buttons, you must download the entire slide file and unzip the files into a directory (., c:\slide) . 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 = | Chapter 2 Elementary Programming Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical problems programmatically. Through these problems, you will learn Java primitive data types and related subjects, such as variables, constants, data types, operators, expressions, and input and output. Objectives To write Java programs to perform simple calculations (§). To obtain input from the console using the Scanner class (§). To use identifiers to name variables, constants, methods, and classes (§). To use variables to store data (§§). To program with assignment statements and assignment expressions (§). To use constants to store permanent data (§). To declare Java primitive data types: byte, short, int, long, float, double, and char (§§). To use Java operators to write numeric expressions (§§–). To display current time (§). To use short
đang nạp các trang xem trước