Review:
1. Better application conditions
When---while until---do--while a fixed number---for
2. Nesting loops
Loop in the loop of the sleeve
Outer walk once, inner layer walk all times
As little as possible.
Break
3. Arrays
int[] arr = new INT[4]; 0,0,0,0
Int[] arr = {1,4,5,7}; 1,4,5,7
int[] arr = new int[]{1,4,5,7}; 1,4,5,7
System.out.println (arr.length);
ARR[0] = 100;
System.out.println (Arr[arr.length-1]);
for (int i=0;i<arr.length;i++) {
Arr[i] = 88;
System.out.println (Arr[i]);
}
System.arraycopy (a,1,a1,0,4);
int[] A1 = arrays.copyof (a,6);
A = arrays.copyof (a,a.length-1); Expansion
Arrays.sort (arr); Ascending
4 numbers, 3 rounds.
Each round starts from the 1th element
And it's the next element than
The number that comes out doesn't play with it.
Schoolboys
1. Method:
1) for encapsulating a specific logic function
2) be as independent as possible and do only one thing
3) can be called multiple times
4) Clear structure and easy maintenance
2. Definition of the method:
Modifier return value type method name (parameter list) {
Method body
}
Attention:
1) The method can have the parameter and can be no parameter, the parameter is more flexible
2) The method can have a return value or it can have no return value:
No return value, return value type write void
Has a return value, the return value type writes the specific data type
3. Invocation of the method
No return value method: Method name (with reference to the parameter);
There is a return value method: Data type variable = method name (with reference to the parameter);
Method name (with reference to the parameter);------almost no
When is the return value? When is there no return value?
Law:
When the method executes, a number in the method is required outside the method,
-----------------have a return value
If the method does not need a number in the method when it finishes executing,
-----------------There is no return value
System.out. println ("HelloWorld");
System. Arraycopy (a,1,a1,0,4);
Arrays. Sort (arr);
Double b = Math. sqrt (49);
int[] A1 = Arrays. CopyOf (a,a.length+1); Have a reference
int num = scan. Nextint ();
Double dou = scan.nextdouble ();
Double A = Math. Random (); No reference
0 to 0.999999 ...
can use the program more flexible
Main () {
Query ();
Withdraw money ();
Transfer ();
}
Query () {
Check the password ();
}
Withdraw Money () {
Check the password ();
}
Transfer () {
Check the password ();
}
Check password () {
}
Method is called---
System.out.println ("HelloWorld");
System.arraycopy (a,1,a1,0,4);
Arrays.sort (arr); No return value void
int num = Scan.nextint ();
Double dou = scan.nextdouble ();
Double A = Math.random ();
Double b = math.sqrt (25);
int[] A1 = arrays.copyof (a,a.length+1); has a return value
Can I take the money? No return value----return value
Can I save money? No return value----no return value
Method is done only once, but it was adjusted 10 times.
Bubble
A () {
Saving
}
B () {
Withdraw money
}
C () {
Transfer
}
Zhang San: Tune A ()/b ()/C ()
John Doe: Tune A ()
Harry: Tune B ()
Main () {
Save money ()----1 lines
Money transfer ()----1 lines
Turn account ()----1 lines
}
Save money () {
2000 Rows
}
Withdraw Money () {
2000 Rows
}
Transfer () {
10000 rows
}
Prime number/Prime: Only 1 is divisible by itself
5 is prime number
5%2/3/4 are not allowed to 0
7 is prime number
7%2/3/4/5/6 are not allowed to 0
8 Not prime
8%2/3/4/5/6/7, if you have 0, it's not prime.
9 Not prime
9%2/3/4/5/6/7/8, if you have 0, it's not prime.
Summarize:
1. As long as there are 0 of the surplus, it is not prime.
2. The remainder is not 0, it is prime
Not a single judgement can get the final result------switch
NUM%51/52/53/54------definitely not 0.
num=100;
I=2/3/4/.../98/99
i=2/3/4/.../49/50
---5
6---
---2/3/4/5/6/7/8/9/10
MATH.SQRT (100)
day006--20150806