java5 예외처리 2( throw, throws, finally ) 예외처리 1( try-catch, printStackTrace(), getmessage() ) 예외 클래스의 계층 구조 모든 예외의 최고 조상은 Exception클래스이다. Exception -- IOException -- ClassNotFoundException -- ... -- RuntiomeException ㄴ ArithmeticException ㄴ ClassCastException ㄴ NullpointException ㄴ ... ㄴ I bohyeon2.tistory.com 예외 발생시키기 키워드 throw를 사용하여 프로그래머가 고의로 예외를 발생시킬 수 있다. 1. 먼저, 연산자 new를 이용하여 발생시키려는 예외 클래스의 객체를 만든다. 2. 키워드 throw를 이용하여 예외를 발생시킨다. E.. 2022. 12. 11. 예외처리 1( try-catch, printStackTrace(), getmessage() ) 예외 클래스의 계층 구조 모든 예외의 최고 조상은 Exception클래스이다. Exception -- IOException -- ClassNotFoundException -- ... -- RuntiomeException ㄴ ArithmeticException ㄴ ClassCastException ㄴ NullpointException ㄴ ... ㄴ IndexOutOfBoundsException 예외처리, try-catch문 예외처리란, 프로그램 실행 시 발생할 수 있는 예기치 못한 예외의 발생에 대비한 코드를 작성 하는 것. 예외의 발생으로 인한 실행 중인 프로그램의 비정상 종료를 막고, 정상적인 실행상태를 유지할 수 있도록 하는 것이다. public static void main(String[] args.. 2022. 12. 11. 입력 받은 문자열에 특정 문자가 몇 개 인지 입력 받은 문자열에 특정 문자가 몇 개 인지 import java.util.Scanner; public class Main { public int solution(String str, char t) { int answer = 0; //대문자로 바꾸어 주는 toUpperCase() str = str.toUpperCase(); t = Character.toUpperCase(t); System.out.println(str +"/"+t); //for (int i = 0; i < str.length(); i++) { //if (str.charAt(i) == t) //answer++; //} //향상된 포문으로 해보기 for(char x : str.toCharArray()) { if(x==t) answer++; }.. 2021. 9. 30. 팩토리얼 ex) 5! = 5 * 4 * 3* 2* 1 Scanner sc = new Scanner(System.in); int input = sc.nextInt(); int accNum = 1; for (int j=1 ; j 2021. 9. 28. char배열을 String으로 바꾸기 char[] charArray = { 'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd' }; String str = new String(charArray); System.out.println(str); //HelloWorld 로 찍힌다. 2021. 9. 28. 이전 1 다음