java-based day4

04.01_Java language basis (using the format and structure of the cycle and for an overview statement)

  • A: Classification of the cyclic structure

    • for,while,do...while

  • B: cyclic structure format for statement:

  • for (initialization expression; conditional expression; expression after cyclic operation) {loop body;}

  • C execution process:

    • a: perform the initialization statement

    • b: performing determination conditional statements, see the return value is true or false

      • If it is true, execution continues

      • If it is false, it is the end of the cycle

    • c: perform loop statement;

    • After the execution cycle operation expression: d

    • e: B back to continue.

  • D: Case presentation

    • Output 10 "helloworld" in the console

04.02_Java Language Infrastructure (loop structure for the Exercise of the statement of acquiring data)

  • A: Case presentation

    • Required: Please console output data 1-10

    • Required: Please output data 10-1 in the console

  • B: Notes

    • a: to determine whether simple or complex conditional statement is the result of type boolean.

    • b: If the statement is a loop statement, the braces can be omitted; if multiple statements, the braces can be omitted. We recommend that you never omitted.

    • c: In general: There will be no opening brace semicolon, the semicolon there will be no opening brace

04.03_Java language basis (sum idea of ​​circular structure for the Exercise of the statement)

  • A: Case presentation

    • Requirements: The data obtained between 1-10 and

  • B: Students practice

    • Demand: find and even-numbered 1-100

    • Demand: find the odd and 1-100

04.04_Java language foundation (practice of daffodils loop structure for statement)

  • A: Case presentation

    • Demand: the output of all the "narcissistic number" in the console

    • Called a three-digit number daffodils means that the digits of the cube and is equal to the number itself.

    • Example: 153 is a number daffodils.

    • 153 = 111 + 555 + 333 = 1 + 125 + 27 = 153

04.05_Java language basis (statistical idea of ​​circular structure for the Exercise of the statement)

  • A: Case presentation

    • Requirements: Statistics, "the number of Narcissus" total number of

04.06_Java language foundation (basic format and structure while using a loop statement)

  • Format A: cyclic structure while statement: The basic format of the while loop: while (judgment condition statement) {loop statement;}

    Full format: initialization statement; the while (judgment condition statement) {      loop statement;      controlling conditional statement; }





  • B: execution process:

    • a: perform the initialization statement

    • b: performing determination conditional statements, see the return value is true or false

      • If it is true, execution continues

      • If it is false, it is the end of the cycle

    • c: perform loop statement;

    • d: execution control conditional statements

    • e: B back to continue.

  • C: Case presentation

    • Required: Please console output data 1-10

04.07_Java language basis (exercise cycle structure while statement)

  • A: sum thinking

    • Seeking 1-100 sum

  • B: Statistical Thinking

    • Statistics "number of Narcissus" total number of

04.08_Java Language Infrastructure (looping structures do ... basic format and use while statements)

  • A: looping structures do ... while statement format:

  • loop do {statement;} while (judgment condition statement);


    Full format;
    initialization statement;
    do {
    loop statement;
    controlling conditional statement;
    } the while (judgment condition statement);
  • B: execution process:

    • a: perform the initialization statement

    • b: performing loop statement;

    • c: execution control conditional statements

    • d: judging the conditional statement execution, see the return value is true or false

      • If it is true, execution continues

      • If it is false, it is the end of the cycle

    • e: b back to continue.

  • C: Case presentation

    • Required: Please console output data 1-10

04.09_Java language basis (difference between the loop structure three loop statements)

  • A: Case presentation

    • Three loop difference statement:

    • do ... while loop executes loop body at least once.

    • And for, while loops must first determine whether the conditions established, and then decide whether to execute the loop body statement.

  • B: Case presentation

    • for and while loops difference:

      • A: If you want to at the end of the cycle, continue to use that variable controlled conditions, using a while loop, or else use the for loop. I do not know who will use a for loop. Because the variable early disappeared from memory, you can improve memory usage efficiency.

04.10_Java language basis (infinite loop cycle considerations of structure)

  • A: Be sure to pay attention to control problems that variable control of conditional statements, do not lose it, otherwise it is easy endless loop.

  • B: The two most simple infinite loop format

    • while(true){...}

    • for(;;){...}

04.11_Java Language Infrastructure (cyclic structure nested loop output stars 4 rows and five columns)

  • A: Case presentation

    • Required: Please outputs a 4 row 5 stars (*) in the pattern.

    • Figure: * * * *


      Note:
      System.out.println ( "*"); and System.out.print ( "*"); the difference
  • B: Conclusion:

    • An outer loop controlling the number of lines, number of columns within the control loop

04.12_Java Language Infrastructure (output loop nest cyclic structure equilateral triangle)

  • A: Case presentation

  • Required: Please output the following form * ** *** *

04.13_Java Language Infrastructure (cyclic structure multiplication table)

  • A: Case presentation

    • Demand: the output of the multiplication table in the console.

  • B: Code Optimization

  • Note: '\ x' x denotes any, \ is the escape symbol, a practice known as transfer characters.


    '\ t' position of the tab key
    '\ r' Enter
    '\ n' new line
    '\ "'
    '\' '

04.14_Java language basis (control jump statements break statement)

  • A: break usage scenarios

    • And the cycle can only switch

04.15_Java language basis (control jumps statement continue statement)

  • A: continue usage scenarios

    • Only in the loop

04.16_Java language basis (control jumps statement label)

  • Label: mark a cycle of its control

  • Label composition rules: in fact valid identifier

  • class Demo3_Mark {// mark marker


    static void main public (String [] args) { / * Outer: for (int I =. 1; I <= 10; I ++) {// A numeral is, as long as the legal identifier to System.out. the println ( "I =" + I); Inner: for (int. 1 = J; J <= 10; J ++) { System.out.println ( "J =" + J); BREAK Outer; } *} / System.out.println ( "Hello everybody"); http://www.heima.com System.out.println ( "is really good"); }


















    }

04.17_Java language basis (control adjustment statement Exercise)

  • A: Exercises

  • for (int x = 1; x <= 10; x ++) {if (x% 3 == 0) {// Fill the code here} System.out.println ( "Java base classes");


    I want to output two times in the console: "Java foundation classes"
    I want to output seven times in the console: "Java foundation classes"
    I think 13 times the output in the console: "Java foundation classes"

04.18_Java language basis (control jumps statement return statement)

  • A: The role of return

    • return

    • In fact, its role is not the end of the cycle, but the end of the method.

  • B: Case presentation

    • The difference between the return and break and continue?

    • return is the end of the process

    • break is out of the loop

    • continue is to terminate this cycle continues for the next cycle

04.19_Java language base (method overview and formatting instructions)

  • A: Why should Method

    • Improve the reusability of code

  • B: What is the method

    • Completion of a particular function block.

  • Method format: C

  • Modifier return type method name (parameter type parameter name 1, parameter type parameter name 2 ...) {statements method body; return return value;}

  • D: Method Format Description

    • Modifiers: Currently on the use of public static. We'll explain in detail later in other modifiers.

    • Return Value Type: Results of that data type.

    • Method name: conform to the naming rules. The convenience of our call.

    • parameter:

      • The actual parameters: that is actually involved in operations.

      • Formal parameters; the method is defined for receiving the actual parameter.

    • Parameter type: it is the data type of the parameter

    • Parameter name: variable name is

    • Method body statement: is the complete code for the function.

    • return: the end of the process.

    • Returns: is the result of the function, the return gives the caller.

04.20_Java language basis (summation of the case and its method call)

  • A: How to write a method

    • 1, a clear return type

    • 2, clear the argument list

  • B: Case presentation

    • Demand: Demand and the data of the two cases

  • C: graphic method calls

04.21_Java language basis (Note Method)

  • A: Method Invocation (specific return value)

    • a: a separate call, generally does not make sense, it is not recommended.

    • b: output calls, but not good enough. Because we may need further action on the results.

    • c: Assignment call recommendations.

  • B: Case presentation

    • a: method does not call does not perform

    • b: same level method and the relationship is not nested definitions

    • c: the time between the method parameter defined, separated by commas

    • d: method is invoked in transmitting the data types do not

    • e: If the method has a clear return value must be a return value back

04.22_Java language basis (exercise method)

  • A: Case presentation

    • Demand: two keyboard input data and returns the larger of two numbers

  • B: Case presentation

    • Requirements: two keyboard input data, compare two numbers are equal

    • import java.util.Scanner;


      Test1_Method {class public static void main (String [] args) { Scanner Scanner new new SC = (the System.in); // Create Object keyboard input System.out.println ( "Enter first integer:") ; int x = sc.nextInt (); // x will be an integer in the keyboard input storage System.out.println ( "Please enter the second integer:"); int sc.nextInt Y = (); // the keyboard input integer stored in y // int max = getMax (X, y); //System.out.println(max); Boolean isEquals = B (X, y); the System.out. the println (B); } / * return value greater even integers 1, return type int clear 2 clear parameter list int a, int b
























      * /
      Public static int getMax (int a, int b) {
      return A> B A:? B;
      } / * determines two integers are equal 1, return type Boolean clear 2 clear parameter list int a, int b * / public static Boolean isEquals (A int, int B) {// if equal isEquals return A == B; } }









04.23_Java language foundation (method of outputting a star and call)

  • A: Case presentation

    • Requirements: keyboard entry of the number of rows and columns, a star in the console output

  • B: Method Invocation :( no return value, void)

    • A separate call

    • Output call (error)

    • Assignment call (error)

04.24_Java language basis (exercise method)

  • A: Case presentation

    • Demand: The keyboard input data corresponding to the output of the multiplication table

04.25_Java language base (method overloading overview and basic use)

  • A: Overview of method overloading

    • Summing Case

      • 2 integer

      • 3 integer

      • 4 integer

  • B: Method overloading:

    • In the same class, the same method name, a list of different parameters. It has nothing to do with the return value type.

    • A list of different parameters:

      • A: number of different parameters

      • B: Different types of parameters

      • C: sequence of the different parameters (operator overloading, but not in development)

04.26_Java language basis (whether comparative data method overload exercise equal)

  • A: Case presentation

    • Requirements: Compare two data are equal.

    • Are two parameters of type int type, two double type, and tested in the main method

04.27_day04 summary

The summary of today's knowledge points again.

Guess you like

Origin www.cnblogs.com/wudaokoubigbrother/p/11841134.html