문자열 s는 한 개 이상의 단어로 구성되어 있습니다. 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 각 단어의 짝수번째 알파벳은 대문자로, 홀수번째 알파벳은 소문자로 바꾼 문자열을 리턴하는 함수, solution을 완성하세요.
문자열 전체의 짝/홀수 인덱스가 아니라, 단어(공백을 기준)별로 짝/홀수 인덱스를 판단해야합니다.
첫 번째 글자는 0번째 인덱스로 보아 짝수번째 알파벳으로 처리해야 합니다.

"try hello world"는 세 단어 "try", "hello", "world"로 구성되어 있습니다. 각 단어의 짝수번째 문자를 대문자로, 홀수번째 문자를 소문자로 바꾸면 "TrY", "HeLlO", "WoRlD"입니다. 따라서 "TrY HeLlO WoRlD" 를 리턴합니다.
class Solution {
public String solution(String s) { // s는 한개이상의단어
// 각단어는 하나이상의 공백문자 , 각단어의 짝수번째알파벳은 대문자, 홀수번쨰 알파벳은 소문자로 바꾼 문자열리턴
String answer = "";
String[] str = s.split("");
int idx =0;
for (int i=0; i<str.length; i++) {
if (str[i].equals(" ")) {
idx=0;
} else if(idx % 2 ==0) {
str[i] = str[i].toUpperCase();
idx++;
} else if(idx % 2 != 0) {
str[i] = str[i].toLowerCase();
idx++;
}
answer += str[i];
}
return answer;
}
}
class Solution {
public String solution(String s) {
String answer = "";
int cnt = 0;
String[] array = s.split("");
for(String ss : array) {
cnt = ss.contains(" ") ? 0 : cnt + 1;
answer += cnt%2 == 0 ? ss.toLowerCase() : ss.toUpperCase();
}
return answer;
}
}
자릿수 더하기
문제 설명
자연수 N이 주어지면, N의 각 자릿수의 합을 구해서 return 하는 solution 함수를 만들어 주세요.
예를들어 N = 123이면 1 + 2 + 3 = 6을 return 하면 됩니다.
제한사항
N의 범위 : 100,000,000 이하의 자연수
입출력 예

입출력 예 설명
입출력 예 #1
문제의 예시와 같습니다.
입출력 예 #2
9 + 8 + 7 = 24이므로 24를 return 하면 됩니다.
public class Solution {
public int solution(int n) {
int answer =0;
while (n > 0) {
answer += n%10;
n/=10;
}
return answer;
}
}
class Solution {
public int[] solution(long n) {
// long -> String
String s =String.valueOf(n);
//reverse 메소드를 사용하기위해 스트링빌더 인스턴스생성
StringBuilder sb = new StringBuilder(s);
// 문자열뒤집기
sb = s.reverse();
String[] stirngArr =sb.toStirng().split("");
//문자열 길이 만큼 배열 길이 할당
int[] answer = new int[sb.length()];
// String -> int -> int[]
for (int i=0; i < sb.length(); i++) {
answer[i] = Integer.parseInt(stringArr[i]);
}
return answer;
}
}
class Solution {
public int[] solution(long n) {
// 문자열 + 숫자 = 문자열
String a = "" + n;
int[] answer = new int[a.length()];
int cnt=0;
while(n>0) {
// 1) 12345 % 10 =5
// 2) 1234 % 10 = 4
// 3) 123 % 10 =3
// 4) 12 % 10 =2
// 1) 1 % 10 =1
answer[cnt]=(int)(n%10);
n/=10;
System.out.println(n);
cnt++;
}
return answer;
}
}
-생각해야할것
class Solution {
public long solution(long n) {
long answer = 0;
return answer;
}
}

public class Main {
public int solution(int[] arr1, int[] arr2) {
int answer =0;
for (int i=0; i<arr1.length; i++) {
if (arr2[i] >=29) {
answer += arr2[i] - arr1[i];
} else {
answer += arr2[i] -arr1[i];
}
}
return answer;
}
public static void main(String[] args) {
Main method = new Main();
int[] arr1 = {9, 9, 9, 9, 7, 9, 8}; //체크인
int[] arr2 = {23, 23, 30, 28, 30, 23, 23}; // 체크아웃
System.out.println(method.solution(arr1, arr2));
}
}

import java.time.DayOfWeek;
import java.time.LocalDate;
public class Main {
public String solution (int month, int day) {
// LocalDate 생성 - 날짜 지정
LocalDate date = LocalDate.of(2022, month, day);
// System.out.println(date);
// targetDate = 98일 이후 날짜
LocalDate targetDate = date.plusDays(98);
// targetDate에서 월 뽑아내기
int getMonth = targetDate.getMonthValue();
// targetDate에서 일 뽑아내기
int getDay = targetDate.getDayOfMonth();
return getMonth + "월 " + getDay + "일";
}
public static void main(String[] args) {
Main method = new Main();
System.out.println(method.solution(6, 22));
}
}