자바

Test

package java14;

//debug(디버그)
//중단점(Break Point)
public class Test {
	public static void main(String[] args) {
		int i=0;
		for(i=0; i<=10; i++);
		{
			System.out.println(i);
		}		
	}
	
}

 

 

Test2

package java14;

public class Test2 {

	static void print(int[] nums){
		for(int n: nums){
			System.out.println(n);	
		}
	}
	
	public static void main(String[] args) {
		//step into(F5) : 다른 method 로 이동
		//step over(F6) : 현재 라인만 실행
		// 다른 method 로 가지 않음
		int[] n ={1, 2,3, 4, 5};
		print(n);
	}
	
}


 

 

BadIndex

package java14;

public class BadIndex {

	public static void main(String[] args) {
		int[] array =new int[10];
		for(int i=0; i<10; i++){
			array[i]=0;
		}
		
/*		Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 12
		at java14.BadIndex.main(BadIndex.java:11)
*/
	
		//F3 코드 보기  , F4 계층구조
		try {
	
			int result =array[12]; //예외 코드 발생
			System.out.println(result);
		} catch (Exception e) { // 예외가 발생하면 	catch 절이 실행됨
			System.out.println("배열의 인덱스가 잘못 되었습니다.");
		}
		
		System.out.println("프로그램 종료");
		
	}
	
}

/*
출력 =>
배열의 인덱스가 잘못 되었습니다.
프로그램 종료

*/

 

 

 

 

 

 

 

 

 

 

 

about author

PHRASE

Level 60  머나먼나라

행복은 자기의 생각에서 나타나는 것이 아니고, 다른 사람과 비교했을 때만 깨달아지는 것이다. -새뮤엘 존슨

댓글 ( 4)

댓글 남기기

작성