본문 바로가기

Java

[Programmers] Level1. 완주하지 못한 선수 (Java) 문제설명 ) 풀이 CODE ) 더보기 import java.util.HashMap; class Solution { //두 개의 문자열 배열을 비교하여 중복되지않는 1개의 문자열 리턴 public String solution(String[] participant, String[] completion) { String answer = ""; //두개의 문자열 index 에 +1또는 -1을 해줄 Hash 선언 HashMap cnt = new HashMap(); //participant 의 인덱스에 맞춰 +1 for (String player : participant) { //getOrDefault 를 통하여 중복 검사 cnt.put(player, cnt.getOrDefault(player, 0) + 1); }.. 더보기
[Programmers] Level1. 모의고사 (Java) Level1. 모의고사 문제설명 ) 풀이Code ) 더보기 import java.util.ArrayList; public class Solution { public int[] solution(int[] answers) { int[] a = new int[] {1, 2, 3, 4, 5}; int[] b = new int[] {2, 1, 2, 3, 2, 4, 2, 5}; int[] c = new int[] {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; //제시된 정답규칙 int[] score = new int[3]; //세 학생의 점수 비교를 위한 배열 for (int i=0; i 더보기
두 개 뽑아서 더하기 import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Solution { public int[] solution(int[] numbers) { List list = new ArrayList(); for (int i=0; i 더보기
[JSP] request 객체 Request 객체 : 사용자(클라이언트)의 요청을 관리하는 객체 관련메소드 getContextPath() : 웹 어플리케이션의 컨텍스트 패스를 얻어올 때 사용하는 메소드 getMethod() : get방식과 post방식을 구분하기 위해서 사용하는 메소드 getSession() : 세션 객체를 얻을 때 사용하는 메소드 getProtocol() : 해당 프로토콜을 얻어올 때 사용하는 메소드 getRequestURL() : 요청한 URL을 얻어올 때 사용하는 메소드 getRequestURI() : 요청 URI를 얻어올 때 사용하는 메소드 getQueryString() : 파라메터와 값을 String 으로 받을때 사용하는 메소드 실행결과 더보기
[JAVA] 자바 해쉬 맵 ( Java HashMap ) HashMap : Map 인터페이스의 한 종류로써 Key와 Value 값으로 데이터를 저장하는 형태. (검색에 용이하다.) [Key,Value] 한쌍 Key는 중복이 불가능하다. (Set) [ 중복된 key값을 입력하게 될경우 이전의 key값이 사라지고 최근입력된 key값으로 덮어씌어진다.] Value는 중복이 가능하다. (Collection) key | hashtable | value ┗ key와 value는 서로 hashtable 을 거친다. Map 자료구조는 순서를 따지지 않기 때문에 Set으로 묶은 후 Iterator를 통해 순서를 부여받아서 나와야한다. 사용방법 ) : HashMap 객체명 = new HashMap(); HashMap 객체명 = new HashMap(용량);.. 더보기
[JAVA] 자바 리스트 앤 셋 ( Java List And Set ) List And Set : Set은 검색에 목적이 있기 때문에 순서 정보를 관리할 필요가 없어 데이터 크기에 상관없이 검색에 걸리는 시간이 매우 짧다. 반면, List는 index를 관리해야 하기 때문에 시간이 오래 걸린다. 그러므로 기능적 차이가 없다면 HashSet을 써야한다. (검색만을 위한 기능이 필요하다면 List보다는 Set을 쓰는 것이 유리하다.) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 public class ListAndSet { public static void main(String[] args) { final int SIZE = 10_000_000; final List arrayList = n.. 더보기
[Java] 정올기초다지기 함수3-자가진단03 12345678910111213141516171819202122232425package 함수3.자가진단03; import java.util.Scanner; public class Main { static int sum =0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); recursive(num); sc.close(); } public static void recursive(int num) { if(num == 0) { System.out.println(sum); return; } else { sum += num; recursive(num-1); } }} 더보기
[Java] 정올기초다지기 함수3-자가진단02 12345678910111213141516171819202122package 함수3.자가진단02; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); recursive(num); sc.close(); } public static void recursive(int num) { if(num == 0) { return; } else { System.out.print(num+" "); recursive(num-1); } }} > num를 먼저 출력한뒤, 재귀함수를 호출할때에 num-1을 해주어 num값.. 더보기