목록Programing Language/JAVA STUDY (59)
습관제작소
문제46(리턴, 반환 '정수') 2개의 정수형 값을 리턴하는 메서드를 구현하시오. import java.util.Arrays; public class Java100_method_TwoReturn1 { public static int[] testMethod(){ int num1 =100; int num2 =200; int num3 =300; return new int[]{num1, num2, num3}; } public static void main(String[] args) { //1. 배열 변수선언 >> 메서드로 부터 반환받을 값이 배열이기 때문에 int result[]= testMethod(); //2. 출력 System.out.println(result[0]+" "+result[1])..
문제44(Call by reference 1) 메인 메서드에서 100을 보냈을 때 깞이 수정되게끔 Call by reference 방식으로 코드를 수정하시오. public class Java100_method_MethodCall2 { public static void sum(Integer a){ a+=400; System.out.println(a); //주소값이 찍히는게 아니라 100이란 값,,,찍힌다. } public static void main(String[] args) { //1. 변수 선언 및 메서드 호출 //Wrpper 클레스의 lnteger 클래스 타입으로 변수 a를 선언하고, //new로 객체를 생성하여 해당 주소값을 메서드로 보낸다 Integer a= new Integer(100); su..
문제43(static 선언 x) static 선언이 안되어있는 메서드를 사용하는 방법에 대해서 코드 구현 클레스명.메서드() 이용하여 구현 public class Java100_method_ExamStatic2 { public void helloWorld(){ System.out.println("Hello, World~"); } public static void main(String[]args){ //1. 메서드 호출 //helloWorld(); //메인 메서드는 static 메서드만 호출할 수 있기 떄문에 에러~ //2. 객체 생성 후 메서드 호출 Java100_method_ExamStatic2 jes = new Java100_method_ExamStatic2(); jes.helloWorld(); } ..
문제40(메서드의 구현 유형2) -반환값 >>>x 받는 인자값>>>o public class Java100_method_Exam002 { public static void plusMethod(int a,int b){ //단순 출력 System.out.printf("인자로 넘겨받은 2개의 %d과 %d입니다.%n", a,b); //연산 출력 int rst = a+b; System.out.println("두수를 더한 값은 = " + rst); } public static void main(String[] args) { //1. 반환값 >>>x 받는 인자값>>>o //메서드가 받는 인자값이 있다는 것은 호출부에서 파라미터 값을 넘긴다는 뜻. int a =100, b=200; plusMethod(a,b); } }..