一、IDEA
1.下载方式
可自行去某宝搜索,或者按照网上教程下载
2.快捷键
1、Alt + Enter : 导入包,自动修复代码(不包括书写错误)
2、Ctrl + Y:删除光标所在行
3、Ctrl + D : 复制光标所在行的内容,并插入到光标位置下面
4、Ctrl + Alt +L :格式化代码(对齐,规范代码格式)
5、Ctrl + Z : 退回到上一步操作
6、Ctr + / :单行注释
7、Ctr + Shift + / :多行注释
注意:重复操作即可取消注释
8、Atl + Ins :自动生成代码,toString,get,set等方法
9、Alt + Shift + 上下箭头:移动当前代码行
10、Fiie --> setting: 可以进行字体(Fonts)、快捷键(keymap)等修改
11、导入Modules : File --> Project Settings --> Modules -->点击左上方+号 -->选择Import Module -->选择Module文件所在位置
二、方法
1.方法定义
- 方法是若干语句的功能集合
- 方法包括:
A、参数:就是进入方法的数据
B、返回值:就是从方法中出来的数据 - 定义方法的完整格式:
修饰符 返回值类型 方法名称 (参数类型 参数名称,…){
方法体
return 返回值;
}
public static 方法名称 (参数类型 参数名称,...){
方法体;
}
修饰符:现阶段的固定写法:public static
return :两个作用,第一停止当前方法,第二将后面的返回值还给调用处
2.方法调用的三种格式
- 单独调用:方法名称(参数);
- 打印调用:System.out.println(方法名称(参数));
- 赋值调用:变量类型 变量名称 = 方法名称(参数);
代码示例:
* 求最大值
*
*/
public class MethodDemo01 {
public static void main(String[] args) {
//单独调用
operator3();
//打印调用
System.out.println(operator3());
//赋值调用
int a = operator3();
}
// 求三个数的最大值
public static int operator3(){
int a = 1;
int b = 9;
int c = 3;
int max;
max = a > b ? a : b;
max = max > c ? max : c;
return max;
}
}
3.方法重载
- 方法重载(Overload):多个方法的名称一样,但是参数列表不同
例如:
sum(int a)
sum(double a)
sum(int a,double b)
sum(double b,int a)
- 方法重载的相关因素
A、参数个数不同
B、参数类型不同
C、不同类型的参数顺序不同 - 方法重载的不相关因素
A、返回值类型
B、参数名称
下面
两个方法并不是方法重载,如果同时出现会出现错误
public static int sum(int a){}
public static double sum(int b){}
代码示例:
/**
*
* 方法的重载:存在一个以上的重名方法,但是参数列表不同,
*
* 求最大值
*/
public class MethodDemo02 {
public static void main(String[] args) {
int x = 1;
int y = 9;
int z = 3;
System.out.println("int = "+operator3(x,y,z));
System.out.println("double = "+operator3(1.0,2.0,3.0));
}
public static int operator3(int a,int b ,int c){
int max = a > b ? a : b;
max = max > c ? max : c;
return max;
}
public static double operator3(double a, double b,double c){
double max;
max = a > b ? a : b;
max = max > c ? max : c;
return max;
}
}