문제 풀이/자바
자바 문제 풀이 28
ssoyul
2023. 5. 16. 20:09
public class CharProblem {
public static String howOld(final String herOld) {
int old = (int)(Math.random()*10);
if(old <= 1) {
return old + " year old";
}
return old + " years old";
}
public static void main(String[] args) {
System.out.println(howOld("How old are you?"));
}
}
//바보.. 문제도 안 읽고 이렇게 풀었다
//아래가 정답
public class CharProblem {
public static int howOld(final String herOld) {
String str = herOld.substring(0,1);
return Integer.parseInt(str);
}
}