Introduction to Java: Methods and IDEA Environment

Five days countdown, come on~(๑•̀ㅂ•́)و✧

method

Separate functions

public static void 方法名称() {
    
    }
方法名称();

The method naming rules are the same as variables: the first word is lowercase, and the last letter is uppercase. It
is a function in C.
Methods cannot be nested definitions , but can be nested.

Jshell

Lightweight use, run directly Insert picture description here
from the command line /exit

Type conversion during operation
short a=1;
short b=2;
short result=a+b;//错误写法!
short result=5+8;//正确写法!赋值时会自动对常量进行类型转换
int result=a+b;//正确写法!

When short/byte/char operations are automatically promoted to int , the data type of the received value must be int. When
all constants are assigned, the compiler will perform constant optimization (automatic type conversion)

Select structure

The data type in the switch() brackets can only be int/short/char/byte/String/enum
switch can be written in the front (the first time you know...)
Insert picture description here
The statements in do{} must be added with a semicolon at the
end while Semicolon

1 in Java can only be used as a numeric type, not a boolean type,
so the way to write an infinite loop is while ( true )

Getting started with IDEA

After going around for a long time, I finally set up the environment. The basic language of C is really much faster.
Quickly create a main: psvm enter.
Output statement: sout enter.
Automatic repair: option + enter (press simultaneously) to
delete the entire line: command+x to
copy the entire line Line: command+d
Alignment: command+option (press first)+l
Selected area Comment: command+shift+/
move the entire line of code: command+shift+⬆️/⬇️Batch
modification of variable names : fn+shift (press first) + touch F6 on the bar
shows the detailed implementation of the method in the library: control+click the method name

actual use

Print without line
break: System.out.print(); output line break: System.out.println();
fast generation loop: 10.fori carriage return

for (int i = 0; i < 10; i++) {
    
    
        }

It's so easy to use! (Super Loud
Method :

public static 返回类型(参数列表){
    
    
方法体
return 返回值;
}
Overload

The method name is the same, but the parameter list is different
. The number of parameters is different, the type is different, and the order of multiple types is different. All can be overloaded,
but the return value type of the overloaded method cannot be different.
Overloading has nothing to do with modifiers (public)

Guess you like

Origin blog.csdn.net/Rachel_IS/article/details/104390057