So I was experimenting with a permutation algorithm a few days back and discovered something.
int y=5;
chomp(y);
System.out.println(y); Output is still 5. Obviously.
void chomp(int x){
y=y-1;
}
The problem starts here.
char[] a = {'a','b','c'};
chomp(a);
System.out.println(a);
void chomp(char[] a){
char temp = a[1];
a[1]=a[2];
a[2]=temp;
}// It swapped it, But I didnt return anything. And I didnt do "a = chomp(a);"
BUT MY OUTPUT IS acb. WHY??? I tried it with int and nothing affected, From my experience in c and c++ im thinking because char array gives the address or something. But there is no pointers in java right? So how can it be???