본문 바로가기

자바27

[코딩 기초 트레이닝] 첫 번째로 나오는 음수 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/181896 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 해결 : import java.util.stream.IntStream; class Solution { public int solution(int[] num_list) { return IntStream.range(0,num_list.length).filter(i->num_list[i] < 0).findFirst().orElse(-1); } } 2024. 1. 23.
[코딩 기초 트레이닝] 순서 바꾸기 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/181891 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 해결 : import java.util.*; class Solution { public int[] solution(int[] num_list, int n) { List list = new ArrayList(); for(int i = n; i 2024. 1. 23.
[코딩 기초 트레이닝] 왼쪽 오른쪽 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/181890 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 해결 : import java.util.*; class Solution { public String[] solution(String[] str_list) { String[] answer = {}; for (int i = 0; i < str_list.length;i++) { if (str_list[i].equals("l")) { return Arrays.copyOfRange(str_lis.. 2024. 1. 23.
[코딩 기초 트레이닝] 간단한 식 계산하기 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/181865 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 해결 : class Solution { public int solution(String binomial) { int answer = 0; String[] num = binomial.split(" "); int a = Integer.parseInt(num[0]); String op = num[1]; int b = Integer.parseInt(num[2]); if(op.equals("+".. 2024. 1. 14.
[코딩 기초 트레이닝] 특정한 문자를 대문자로 바꾸기 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/181873 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 해결 : class Solution { public String solution(String my_string, String alp) { my_string = my_string.replaceAll(alp, alp.toUpperCase()); return my_string; } } 2024. 1. 3.
[코딩 기초 트레이닝] 길이에 따른 연산 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/181879 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 해결 : class Solution { public int solution(int[] num_list) { int answer = 0; if(num_list.length > 10){ for(int sum : num_list) answer += sum; }else{ answer = 1; for(int multi : num_list) answer *= multi; } return answe.. 2024. 1. 2.
[JAVA] 깊은 복사와 얕은 복사 1차원 배열 복사 얕은 복사란? - 객체의 주소 값을 복사하는 것이다. - 여러 객체가 같은 주소를 참조하기 때문에 하나의 값을 변경하면 다른 대상의 값도 변경된다. - 한 개의 객체 주소를 참조하므로 하나의 객체라고 볼 수 있다. - 하나의 객체로써 사용이 가능하다면 쓸데없이 객체를 복사하여 사용할 필요없지만 이럴 경우 사용한다는 의미가 된다. public class Array_Copy{ public static void main(String[] args) { int[] a = { 1, 2, 3, 4 }; int[] b = a; } } 깊은 복사란? - 객체의 실제 값을 새로운 객체로 복사하는 것이다. - 다른 주소와 같은 값인 객체가 두개 존재하게 된다. - 대개 객체를 복사한다는 말은 얕은 복사가 .. 2024. 1. 2.
[코딩 기초 트레이닝] 소문자로 바꾸기 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/181850 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 해결 : class Solution { public String solution(String myString) { String answer = ""; answer = myString.toLowerCase(); return answer; } } 2024. 1. 1.
[코딩 기초 트레이닝] 대문자로 바꾸기 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/181877 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 해결 : class Solution { public String solution(String myString) { String answer = ""; answer = myString.toUpperCase(); return answer; } } 2024. 1. 1.
[코딩 기초 트레이닝] 원하는 문자열 찾기 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/181878 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 해결 : class Solution { public int solution(String myString, String pat) { int answer = 0; if(myString.toLowerCase().contains(pat.toLowerCase())) answer = 1; return answer; } } 2024. 1. 1.
[코딩 기초 트레이닝] 조건에 맞게 수열 변환하기 1 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/181882 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 해결 : class Solution { public int[] solution(int[] arr) { int[] answer = new int[arr.length]; for(int i =0; i= 50 && arr[i]%2 == 0 ){ answer[i] = arr[i]/2; }else if(arr[i] < 50 && arr[i]%2 != 0){ answer[i] = arr[i]*2; .. 2024. 1. 1.
[코딩 기초 트레이닝] n보다 커질 때까지 더하기 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/181884 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 해결 : class Solution { public int solution(int[] numbers, int n) { int sum = 0; for(int i = 0; i n ){ return sum; } } return sum; } } 복붙하니까 들여쓰기 난감;;하지만 귀찮으니 패스~ 하지만 개발할 때는 이렇게 하면 혼납니다 ㅎㅎ.. if문에서 걸리지 않으면 return하는 부분이 없.. 2023. 12. 28.