IDEA中内容辅助键和快捷键
快速生成main方法:psvm 回车;
快速生成输出语句:sout 回车;
代码补全 ctrl+alt+space;
单行注释:ctrl +/;
多行注释:ctrl + shift + / ;
格式化代码:ctrl +alt + L ;
遍历数组
public class helloworld {
public static void main(String[] args) {
// 定义数组
int[] arr = {1, 22, 33, 44, 55};
for (int x = 0; x < arr.length; x++) {
System.out.println(arr[x]);
}
}
}
数组中取最大值
public class helloworld {
public static void main(String[] args) {
int[] arr = {1, 22, 33, 44, 55};
int max = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
System.out.println(max);
}
}
带参数方法定义和调用
public class helloworld {
public static void main(String[] args) {
// 常量调用
isEvenNumber(10);
// 变量调用
int number = 10;
isEvenNumber(number);
}
// 定义一个方法,该方法接收一个参数,判断该数据是否为偶数
public static void isEvenNumber(int number){
if (number%2==0){
System.out.println(true);
}else {
System.out.println(false);
}
}
}
带返回值方法的练习,两个数中取最大的
public class helloworld {
public static void main(String[] args) {
// 在main()方法中调用定义的方法并使用变量保存
// int result = getMax(a:10, b:20)
// System.out.println(result);
System.out.println(getMax(a:10,b:20));
}
// 定义一个方法获取两个数中较大数
public static int getMax(int a, int b) {
if (a > b) {
return a;
} else {
return b;
}
}
}
遍历数组
public class helloworld {
public static void main(String[] args) {
// 定义一个数组,用静态初始化完成数组元组初始化
int[] arr= {11,22,33,44,55};
// 调用方法
printArray(arr);
}
// 定义一个方法,用数组遍历通用格式对数组进行遍历。
// 明确返回类型为void,参数int[] arr
public static void printArray(int[] arr){
for (int x=0;x
85



