Day 4: Class vs. Instance Task Write a Person class with an instance variable, , and a constructor that takes an integer, , as a parameter. The constructor must assign to after confirming the argument passed as is not negative; if a negative argument is passed as , the constructor should set to and print Age is not valid, setting age to 0.. In addition, you must write the following instance methods:yearPasses() should in.. 더보기 Level 1- 짝수와 홀수 evenOrOdd 메소드는 int형 num을 매개변수로 받습니다. num이 짝수일 경우 Even을 반환하고 홀수인 경우 Odd를 반환하도록 evenOrOdd에 코드를 작성해 보세요. num은 0이상의 정수이며, num이 음수인 경우는 없습니다. 풀이 public class EvenOrOdd { String evenOrOdd(int num) { String result = ""; if (num % 2 == 0){ result = "Even"; } else { result = "Odd"; } return result; } public static void main(String[] args) { String str = "1 2 3 4"; EvenOrOdd evenOrOdd = new EvenOrOdd(); /.. 더보기 Level 1 - 삼각형출력하기 printTriangle 메소드는 양의 정수 num을 매개변수로 입력받습니다. 다음을 참고해 *(별)로 높이가 num인 삼각형을 문자열로 리턴하는 printTriangle 메소드를 완성하세요 printTriangle이 return하는 String은 개행문자('\n')로 끝나야 합니다.높이가 3일때* ** *** 높이가 5일때* ** *** **** ***** 풀이 public class PrintTriangle {public String printTriangle(int num){ String str =""; for(int i =1; i 더보기 이전 1 ··· 37 38 39 40 41 42 43 ··· 53 다음