등록하기 전에 찜찜한 마음에 질문을 새창으로 열어보니... 깔끔한 답변이 먼저 달려있어서 등록 포기.
그냥 평소대로 등록했으면 지식영향력 또 깎일뻔 했네..
A. 질문
첫번째 질문
import java.util.Arrays;
public class Testtest {
public static double[][] test(double[][] x) {
double[][] ans = new double[2][2] ;
return ans ;
}
public static void main(String[] args) {
double[][] s = {{1,2},{3,4}} ;
System.out.print(Arrays.toString(test(s)));
}
}
console
[[D@2a139a55, [D@15db9742]
Arrays.toString을 사용했는데 출력물이 안보입니다.. 왜 그런거고 어떻게 해결 할 수 있나요?
두번째 질문
public static void main(String[] args) {
System.out.print(Arrays.toString(test({{1,2},{3,4}})));
}
이런식으로 함수안에 배열을 직접 입력하는건 왜 안되죠???
부탁드립니다
B. 먼저 등록된 답변
C. 등록하려 했던 내답변
2차원배열 이상은 deepToString() 을 사용해서 값을 불러와야 합니다.
아래를 참고하세요.
1. CLASS
import java.util.Arrays;
public class test_0322_01 {
public static void main(String[] args) {
Testtest t = new Testtest();
double[][] s = {{1,2},{3,4}};
// System.out.print(Arrays.toString(t.test(s)));
System.out.print(Arrays.deepToString(t.test(s)));
System.out.println("\n");
// System.out.print(Arrays.toString(t.test({{1,2},{3,4}})));
/*
double[][] aa = new double[2][2];
aa[0][0] = 9;
aa[0][1] = 8;
aa[1][0] = 7;
aa[1][1] = 6;
System.out.print(Arrays.toString(t.test(aa)));
*/
System.out.print(Arrays.deepToString(t.test(new double[][]{{9,8},{7,6}})));
}
}
class Testtest {
public static double[][] test(double[][] x) {
System.out.println(x[0][0]);
System.out.println(x[0][1]);
System.out.println(x[1][0]);
System.out.println(x[1][1]);
double[][] ans = new double[2][2] ; // ans 2X2 배열 생성.
ans = x; // 새로 생성된 배열에 배열인자 전달.
return ans ;
}
}
2. RUN
1.0
2.0
3.0
4.0
[[1.0, 2.0], [3.0, 4.0]]
9.0
8.0
7.0
6.0
[[9.0, 8.0], [7.0, 6.0]]
// 쓸데없이 소스 꾸미고 여러가지 경우를 보여줄려고 딴짓하다가 계속 늦네..
// 꼭 답변 작성하고, 게시물 등록할때 일이 갑자기 밀려온다..
'course > 지식인' 카테고리의 다른 글
[자바] 아주 간단한거.. (0) | 2016.03.23 |
---|---|
[자바] 특정 클래스의 this 를 public String toString(){ } 반환 (0) | 2016.03.15 |
[자바스크립트] 오늘을 기준으로 한달전 날짜 구하기. (0) | 2016.03.14 |