public class Method { public static void main(String[] args) { int[] arr = {11,22,1,2,33,4}; System.out.println(getMax(arr)); } public static int getMax(int[] arr){ int max = arr[0]; for(int i = 1;i < arr.length;i++){ if(max < arr[i]) max =arr[i]; } //System.out.println(max); return max; } }
Debug:查看代码的执行流程
Debug调试:断点调试
①加断点
②运行看Debug窗口,看变量的变化,console看结果展示,点F7下一步。
③删除断点,鼠标左键,可全部删除。
数组元素前后翻转
public class Method { public static void main(String[] args) { int []arr = {0,1,2,2,5,6,2} ; Scanner fp = new Scanner(System.in); //int n = fp.nextInt(); /*for(int i = 0;i < 7; i++){ arr[i] = fp.nextInt(); }*/ for(int i =0,j = arr.length-1;i <= j; i++,j--){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } for(int i = 0;i < 7;i++){ System.out.println(arr[i]); } }