본문 바로가기

with my rubber duck79

백준 1924 자바 내가 이걸 풀다니 문제 월 일을 입력받고 요일 출력하는 코드 구현하기 (보잘것없는 나의) 답: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); // 달마다 더할 3월 1일 = ( 1월 + 2월 + y) % 7 // 1~7제외 나눈 나머지가 1 월 2 화 3 수 4 목 5 금 6 토 0일 int[] monthDays = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int sum = 0; if (x == 1) { sum = 0; .. 2022. 4. 2.
boolean method 와 return과의 전쟁 기록 이 에러는 에러문이 나오는 그런 에러는 아니고,, 지극히 개인적인 logic error다. 반복문 안의 return값은 인식 못하는 불리언 메서드 반복문 안에있는 return값은 밖에서 인식 못 함. 그래서 타입을 void로 바꿨더니 이번엔 리턴 값이 있으면 안 된다 난리.^^ 어쩌라는겨 반복문 빼주면 리턴타입 =오류 없어짐 그러나 그것은 내가 원하는 로직이 아니었으므로... 이것저것 시도해보다가 그럴싸해 보이지만 심각한 오류를 갖고 있는 코드를 짜게 됨... 잘못된 로직을 소개합니다^^ 이 코드는 완전히 잘못됨 가장 문제되는 부분은 이것. 이 코드은 항상 false를 리턴할 수밖에 없음. 나는 if문을 써서 해당 조건에 false면 false가 나오게 하고 아니면 if문을 빠져나와 밑에 있는 true를.. 2022. 4. 1.
bubble sorting package prob_method.answ; /* * [출력결과] * 내림 차순 결과 31 22 16 11 10 9 오름 차순 결과 9 10 11 16 22 31 */ public class Prob007_method { public static void main(String[] args) { int[] arr = { 10, 22, 9, 16, 11, 31 }; int[] result1 = sort(arr, "desc"); int[] result2 = sort(arr, "asc"); System.out.println("내림 차순 결과"); for (int i = 0; i < result1.length; i++) { System.out.println(result1[i]); } System.out.prin.. 2022. 3. 30.
백준 2739 구구단전문가 나야나 문제 답: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int input = sc.nextInt(); for(int i = 1;i < 10; i++) { int res = input * i; System.out.printf("%d * %d = %d\n",input,i,res); } } } 2022. 3. 29.
백준 2742 기찍 N 답 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int input = sc.nextInt(); for(int i = input;i > 0; i--) { System.out.println(i); } } } 쉽네 2022. 3. 29.
2741 백준 갑자기 쉬운문제 주냐 문제 답 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); for (int i = 1; i 2022. 3. 29.
728x90