코딩테스트

· Algorithm
언어_ 자바 0) 피보나치 수열이란? 피보나치 수열이란 앞의 2개의 수를 합하여 다음 숫자가 되는 수열이다. 1) 재귀 사용 public class Test4 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i=1; i
· Algorithm
🍯 대소문자 구분 없이 문자 찾기 TIP ) 찾고자하는 문자/ 찾을 문자열을 모두 UpperCase 혹은 LowerCase로 맞춰준다 Example public class Test1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String input1 = sc.next(); // Abstract char input2 = sc.next().charAt(0); // a input1= input1.toUpperCase(); // 전체 대문자 만들어주기 -> ABSTRACT input2= Character.toUpperCase(input2); // 문자를 대문자로 만들기 -> A int answer =0; for(..
· Algorithm
📌 toCharArray() 해당 문자열을 문자(char) 배열로 변환해주는 메소드 String str = "Hello"; char[] charArray = str.toCharArray(); for (char c : charArray) { System.out.println(c); } // 출력값 H e l l o 📌 StringBuiler String에서 '+' 와 같은 연산자를 사용하여 불필요한 새로운 객체를 생성하는 방식에서 벗어나 변경 가능한 StringBuilder 객체를 생성하여 문자열 변경의 성능 향상에 도움을 준다. 생성자 // 기본 생성자 StringBuilder sb = new StringBuilder(); 주요 메소드 1. append() : 문자열 추가 StringBuilder sb ..
· Algorithm
언어_자바 프로그래머스_주사위 게임 3 주사위 게임 3이 여러 가정을 생각하는 게 어려웠다 😢 다른 사람들 풀이를 보고 이해하고 풀이 없이 코드를 짜는 방식으로 이번에 진행했다. public class DiceGame3 { public static void main(String[] args) { DiceSolution s = new DiceSolution(); int a = 4; int b = 1; int c = 4; int d = 4; s.diceSolution(a,b,c,d); } } class DiceSolution{ public int diceSolution(int a, int b, int c, int d){ int[] dice = {a,b,c,d}; Arrays.sort(dice); int an..
· Algorithm
언어_자바 프로그래머스_문자열 여러 번 뒤집기 class ReverseWord { public String reverseWord(String my_string, int[][] queries) { StringBuilder result = new StringBuilder(my_string); for (int i = 0; i < queries.length; i++) { int start = queries[i][0]; int end = queries[i][1]; StringBuilder str = new StringBuilder(result.substring(start, end + 1)); // subString(처음(포함), 끝(제외)) 이므로 end+1함으로써 end도 포함됨 str.reverse(); re..
· Algorithm
언어_자바 프로그래머스_배열 만들기 2 import java.util.ArrayList; // 프로그래머스에서 에러가 뜬다면 import 했는지 체크! public class MakeArray { public int[] makeArray(int l, int r) { ArrayList result = new ArrayList(); for(int i = l; i
· Algorithm
언어_자바 이것이 코딩 테스트다_92p~95p 큰 수의 법칙 N: 배열의 크기 M: 숫자가 더해지는 횟수 K: 최대 가능한 연속성 횟수 입력 예시 5 8 3 2 4 5 4 6 public class _92BigNum { static Integer n; static Integer m; static Integer k; static Integer first, second; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); ..
· Algorithm
언어_자바 프로그래머스_수 조작하기2 public class Control2 { public static void main(String[] args) { Test5 t = new Test5(); int[] numLog = {0, 1, 0, 10, 0, 1, 0, 10, 0, -1, -2, -1}; t.test5(numLog); } } class Test5{ public String test5(int[] numLog) { StringBuilder result = new StringBuilder(); // StringBuilder 객체 선언 for(int i= 0; i 0){ int diff = numLog[i] - numLog[i-1]; // 두 값의 차이 if(diff == 1){ result.appen..
· Algorithm
언어_자바 프로그래머스_수 조작하기1 public class Control1 { public static void main(String[] args) { Test4 t = new Test4(); int n = 0; String control = "wsdawsdassw"; t.test4(n, control); } } class Test4{ public int test4(int n, String control) { for (char cmd : control.toCharArray()) { // 문자열을 char 배열로 변환 switch (cmd) { case 'w': n += 1; break; case 's': n -= 1; break; case 'd': n += 10; break; case 'a': n -=..
31daylee
'코딩테스트' 태그의 글 목록 (2 Page)