Day06_ Method _20150806

Source: Internet
Author: User

day06_ Method _20150806

-------------------------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

Demo Code:
Presentation of the package day06;//method public class Methoddemo {public static void main (string[] args) {//say ();//sayhi ();//Compile error, must pass parameter// Sayhi (8); Compilation error, Parameter type mismatch//sayhi ("Zhangsan"); String name= "Zhangsan"//sayhi ("Lisi"); String name= "Lisi"//sayhi ("Wangwu"); String name= "Wangwu"//int num = Getnum ();//system.out.println (num); 88//double d = Plus (5,6); Double num1=5,double num2=6//system.out.println (d); 11//double a = 5.5;//double b = 4.4;//double Dou = Plus (A, b); Double num1=5.5,double num2=4.4//system.out.println (dou); a (); The nested invocation of the method System.out.println ("Over");} public static void A () {System.out.println (111); B (); SYSTEM.OUT.PRINTLN (222);} public static void B () {System.out.println (333); C ();} public static void C () {System.out.println (444);} The parameter has a return value of public static double plus (double num1,double num2) {//double num = Num1+num2;//return num;//return is not num, But that number in Num is return num1+num2; Returns the value of Num1+num2}//no parameter has a return value of public static int Getnum () {//return;//Compilation error, must return a value of//return 5.55;//Compile error, return value type does not match return 88; 1. End methodThe execution of 2. Returns the result (250) to the caller}//has a parameter no return value public static void Sayhi (String name) {System.out.println ("Hello everyone, I'm called" +name); return;//1. Execution of the End method}//no parameter no return value public static void Say () {System.out.println ("Hello everyone, my name is wkj");}


Attached to the small game of guessing the alphabet Source: http://blog.csdn.net/u011637069/article/details/47322099




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Day06_ Method _20150806

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.