# 중첩된 조건문 human 메소드에서 프린트하지 않고 return해서 메인 메소드에서 프린트해보려고 하는데 어떤부분을 건드려야 할지 모르겠습니다.. #### CODE <a class='btn btn-default' href='/codes/77893'>Link</a> ``` public class AverageHeight{ public static void main(String [] args){ human(176.3,true); human(162.7,false); human(171.8,true); human(158.4,false); } public static void human(double height, boolean IsMale){ String gender = ""; String result = ""; if (IsMale) { gender = "남"; if (height >= 173.5) { result = "이상"; } else { result = "이하"; } } else { gender = "여"; if (height >= 160.8) { result = "이상"; } else { result = "이하"; } } System.out.printf("%.1fcm, %s => 평균키 %s\n", height, gender, result); } } ``` #### INPUT ``` ``` #### OUPUT ``` 176.3cm, 남 => 평균키 이상 162.7cm, 여 => 평균키 이상 171.8cm, 남 => 평균키 이하 158.4cm, 여 => 평균키 이하 ```
## 이런 식으로 String.format() 메소드를 사용해 문자열을 만든 뒤, ``` public static String human(double height, boolean IsMale){ String gender = ""; String result = ""; if (IsMale) { gender = "남"; if (height >= 173.5) { result = "이상"; } else { result = "이하"; } } else { gender = "여"; if (height >= 160.8) { result = "이상"; } else { result = "이하"; } } return String.format("%.1fcm, %s => 평균키 %s\n", height, gender, result); } ``` 결과물을 메인 메소드에서 출력해보세요. ``` public static void main(String [] args) { System.out.println(human(176.3,true)); System.out.println(human(162.7,false)); System.out.println(human(171.8,true)); System.out.println(human(158.4,false)); } ```
감사합니다. 이런 방법도 있군요.