package edu.exam05.homework;

import java.util.Arrays;

/*1. 다음 두 개의 static메소드를 가진 ArrayUtility클래스를 만들어보고 사용해보세요
static double[] intToDouble(int[] source);	// int배열을 double배열로 변환
static int[] doubleToInt(double[] source);	// double배열을 int배열로 변환
*/

class ArrayUtility{
	static double[] intToDouble(int[] source) { //int -> double
		
		double[] arr =new double[source.length];
		for(int i=0;i<source.length;i++) {
			
			arr[i] =(double)source[i];
			
		}
		
		return arr;
		
	}
	static int[] doubleToInt(double[] source) {
		
		int[] arr =new int[source.length];
		for(int i=0;i<source.length;i++) {
			
			arr[i] =(int)source[i];
			
		}		
		return arr;	
	}	
}

public class AhnHomework02_1 {
	public static void main(String[] args) {
		ArrayUtility array = new ArrayUtility();
		
		int source1[] = {1,2,3,4,5};
		double source2[] = {1.0,2.0,3.0,4.0,5.0};
		
		System.out.println("Int -> Double");
		System.out.println(Arrays.toString(array.intToDouble(source1)));

		System.out.println("Double -> Int");
		System.out.println(Arrays.toString(array.doubleToInt(source2)));
		
		ArrayUtility.intToDouble(source1);	//static으로 선언해서
	}
}

'etc.. > 1' 카테고리의 다른 글

생성자 클래스 예제  (0) 2020.01.15
static 메소드 예제 2 - 미완성  (0) 2020.01.15
클래스 생성자 예제  (0) 2020.01.15
예제 배열 인덱스 교환 값 바꾸기  (0) 2020.01.15
생성자 예제  (0) 2020.01.14

+ Recent posts