public class EvenOrOdd { public static String even_or_odd(int number) { if(number % 2 == 0){ return "Even"; }else{ return "Odd"; } } } public class EvenOrOdd { public static String even_or_odd(int number) { return (number % 2) == 0 ? "Even" : "Odd"; } } 이거 써봐야지, 마음 먹고 풀지 않는 이상 항상 if문을 쓴 다음에야 삼항연산자가 생각난다... 앞으로는 까먹지 않게 삼항연산자를 써야지
public class AbbreviateTwoWords { public static String abbrevName(String name) { String[] nm = name.split(" "); return (nm[0].charAt(0) + "." + nm[1].charAt(0)).toUpperCase(); } } 대문자 변환!! 이걸 안 해서 왜 안 되냐고 붙들고 있었다
public class CuboidVolumes { public static int findDifference(final int[] firstCuboid, final int[] secondCuboid) { //your code here !! return Math.abs(firstCuboid[0]*firstCuboid[1]*firstCuboid[2] - secondCuboid[0]*secondCuboid[1]*secondCuboid[2]); } }
public class Banjo { public static String areYouPlayingBanjo(String name) { if(name.startsWith("r") || name.startsWith("R")) { return name + " plays banjo"; } else { return name + " does not play banjo"; } } }
package com.codewars.hwtdstrngls; public class RoundToTheNextMultipleOf5 { public static int roundToNext5(int n) { while( n % 5 != 0) n++; return n; } } 몇 줄 안 되는데 여전히 시간이 오래 걸린다 백준 같은 사이트 문제는 더 오래 걸려서 시간이 있는 날 없는 날 백준 / 코드워즈를 왔다 갔다 하는 중
public class Solution { public static String repeatStr(final int repeat, final String string) { String result = ""; if (repeat > 0) { for (int i = 0; i < repeat; i++) { result += string; } } return result; } }