336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
description :
배열을 선언하고 equals를 통해 객체의 call by value와 call by reference 를 연구한다.
source code :
package exam007;
public class exam007 {
public static void main(String[] args) {
int [] myArray = {97, 89, 95};
int [] compHash= {20, 50, 30};
int [] cloneArray = myArray.clone();
int [] refArray = myArray;
System.out.print("myArray 요소 값 : ");
for(int i = 0 ; i < myArray.length ; i++) {
System.out.print(myArray[i]);
if(i == myArray.length) {
System.out.println(' ');
}else{
System.out.print(' ');
}
}
System.out.println('\n');
///////////////////////////////////////////////////////
System.out.print("compHash 요소 값 : ");
for(int i = 0 ; i < compHash.length ; i++) {
System.out.print(compHash[i]);
if(i == compHash.length) {
System.out.println(' ');
}else{
System.out.print(' ');
}
}
System.out.println('\n');
///////////////////////////////////////////////////////
System.out.print("cloneArray 요소 값 : ");
for(int i = 0 ; i < cloneArray.length ; i++) {
System.out.print(cloneArray[i]);
if(i == cloneArray.length) {
System.out.println(' ');
}else{
System.out.print(' ');
}
}
System.out.println('\n');
///////////////////////////////////////////////////////
System.out.print("refArray 요소 값 : ");
for(int i = 0 ; i < refArray.length ; i++) {
System.out.print(refArray[i]);
if(i == refArray.length) {
System.out.println(' ');
}else{
System.out.print(' ');
}
}
System.out.println('\n');
if(myArray.equals(compHash)){
System.out.println("myArray와 compHash는 같다.");
}else {
System.out.println("myArray와 compHash는 같지 않다.");
}
System.out.printf("myArray hash : %d \ncompHash hash : %d \n\n", myArray.hashCode(), compHash.hashCode());
////////////////////////////////////////////////////////
if(myArray.equals(cloneArray)){
System.out.println("myArray와 cloneArray는 같다.");
}else {
System.out.println("myArray와 cloneArray는 같지 않다.");
}
System.out.printf("myArray hash : %d \ncloneArray hash : %d \n\n", myArray.hashCode(), cloneArray.hashCode());
if(myArray.equals(refArray)){
System.out.println("myArray와 refArray는 같다.");
}else {
System.out.println("myArray와 refArray는 같지 않다.");
}
System.out.printf("myArray hash : %d \nrefArray hash : %d \n\n", myArray.hashCode(), refArray.hashCode());
}
}
result :