public class Shape
{
public static void main(String args[]){
int num = 0;
cng(num);
}
public static void cng(int x){
x = 52;
System.out.println(x);
}
}
As you can see, in the cng
Method I set the value of x to 52 and then print out the value of x.
Then, back in the main method, the cng
method is performed on the num
variable.
What I want to do, however is set the value of 52 to x without the System.out.println(x);
function in my cng
method and print out the value in my main
method. How would I go about doing that?
I tried doing
public static void cng(int x){
x = 52;
}
and then
public static void main(String args[]){
int num = 0;
cng(num);
System.out.println(num);
}
but it only prints out a 0
because num is set to 0. I thought that performing cng
on the num
variable would change it to 52, but it doesn't.