斷點調試的作用: A:查看程式的執行流程。 B:調試程式。 i變數只在for迴圈內有效,for迴圈結束後,變數i就消失了。 註意:要想看被調用方法的執行流程,那麼被調用方法也必須要加斷點。 ...
斷點調試的作用:
A:查看程式的執行流程。
B:調試程式。
1 package basic.java; 2 3 public class DebugTest { 4 public static void main(String[] args) { 5 int sum = 0; 6 for (int i = 1; i <= 5; i++) { 7 sum+=i; 8 } 9 System.out.println(sum); 10 } 11 }
i變數只在for迴圈內有效,for迴圈結束後,變數i就消失了。
1 package basic.java; 2 3 import java.util.Scanner; 4 5 public class DebugTest2 { 6 @SuppressWarnings("resource") 7 public static void main(String[] args) { 8 Scanner sc = new Scanner(System.in); 9 10 System.out.println("請輸入第一個數:"); 11 int a = sc.nextInt(); 12 13 System.out.println("請輸入第二個數:"); 14 int b = sc.nextInt(); 15 16 int c = sum(a, b); 17 System.out.println(c); 18 } 19 20 public static int sum(int a, int b) { 21 int c = a + b; 22 return c; 23 } 24 }
註意:要想看被調用方法的執行流程,那麼被調用方法也必須要加斷點。