본문 바로가기
반응형

분류 전체보기645

2025년 1회 정보처리기사 실기. Java 오버로딩 문제 오버로딩: 함수 이름은 똑같은 데 안에 들어가 있는 변수가 다른 거. public class Weekendcode { public static void main(String[] args) { 메인함수 시작점. System.out.println(calc("5")); 문자열5에 해당하는 파라미터 함수 호출하라.} static int calc(int value) { calc(4)를 먼저 해보면 if(value 4조건이 맞지 않으니까 다음줄로 이동하기. return calc(value-1) + calc(value-2); calc(3)+calc(2)가 됨. 또 calc(int value) 메소드 또 호출해줘야하넹}calc(4)calc(3)+calc(2)2+1=3calc(3)calc(2)+calc(1)1+1.. 2025. 4. 26.
2025년 1회 정보처리기사 실기. Java Math.max(), 재귀함수 문제 public class Maximal { static int func(int[]a, int st, int end) { func 메소드. (int[]a=values 배열주소, int st=0, int end=values.length-1=5-1=4) if(st>=end) return 0; st가 end보다 크거나 같으면 return 0하라.하지만 0>=4 틀리니까 아래줄로 이동하게됨. int mid=(st + end) /2; st+end=0+4=4 니까 mid=4/2=2 return a[mid]+Math.max(func(a, st, mid), func(a, mid+1, end)); a[2]=8+재귀함수 2개 등장! (처음에 이거 보자마자 멘붕옴... 근데 유툽 해설 보니까 생각보다 쉬워서 광광 우러따.. 2025. 4. 26.
2025년 1회 정보처리기사 실기. Java static 메서드 문제 class Parent { static int total=0; Child를 태어나게 하려면 Parent가 먼저 태어나야함. (뭔 소리임?ㅋㅋ 자바 어려워... 암튼 부모 클래스 먼저 하고 나서 자식 클래스 들어가야 한대...아오 내가 이걸 우찌 아냐) int v =1; public Parent() { total+=(++v); total=total+(++v) 니까 total=0+2=2 showValue();} public void showValue() { total+=total; }} class Child extens Parent { intv=10; public Child() { Child 클래스의 생성자. v+=2; v=v+2=10+2=12 total+=(v++); total=t.. 2025. 4. 26.
25년 1회차 정보처리기사 실기. Java try-catch 문제 Java try-catch-finally 문제public class DivisionDemo{ public static void main(Strin[] args){ try{ int a = 5, b =0; System.out.print(a/b); try 안에는 오류 발생 예상되는 코드 넣음. a/b=5/0 0으로 나누면 뭐든 0나오는 오류 발생.} catch (ArithmeticException e) { 0으로 나누는 오류는 ArithmeticException에 해당함. System.out.print("출력1");} catch (NullPointerExcepion e) { System.out.print("출력2");} catch (ArrayIndexOutOfBoundsExcepion e) .. 2025. 4. 26.