读完本文你会了解到:
Primitive types:
data type | representation |
---|---|
byte | 8-bit |
char | 16-bit |
short | 16-bit |
int | 32-bit |
float | 32-bit |
long | 64-bit |
double | 64-bit |
声明语句:声明语句将一个变量名和一个类型在编译时关联起来。Java是一种强类型的语言,因为Java编译器会检查类型的一致性。
循环语句:
- break语句,立即从循环中退出
- continue语句,立即开始下一循环
Array
Definition:
An arroy stores a sequence of values that are all of the same type.if we have N
values,we can use the notation a[i]
to refer i
th value of i
from 0
to N-1
.
Making an array involves three distinct steps:
- Declare the array name and type
- Creat the array
- Initialize the array values
Example:
|
|
Using:
Java does automatic bounds checking-if you access an array with an illegal index your program will terminate with anArrayIndexOutOfBoundsException
Alising(混淆):
An array name refers to the whole array-if wo assign one array name to another,then both refer to the same array,as illustrate in the following code fragment.
|
|
有关数组的典型静态方法实现:
Static method
Defining a static method:
A method encapsulates a computation that is defined as a statements. A method takes arguments and computes a return value of some data type or causes aside effect
.- Java method have features:
- Arguments are passd by value.
- Method names can be overloaded.
- A method has a signal return but may have multiple return statements.
- A method can have side effects.
Binary Search
|
|
Web Exercises
1 Wget. Write a program Wget.java
that reads in data from the URL specifiedon the command line and saves it in a file with the same name.
2 编写一段代码,将一个正整数N用二进制表示并转换为一个String
类型的值s。
同理,用m进制表示,就将2换成m进制
3 Right triangle.Write a client RightTriangle.java that draws a right triangle and a circumscribing circle.
4 Bouncing ball.Write a program BouncingBall.java that illustrates the motion of a bouncing ball
参考
static method: