Simple calculation method problem.
Code:
public class CalculationExample{
//declare global variable
static int y;
public static void main(String[] args){
addition(4, 3); //method called with two values assigned
}//end main
public int addition( int a, int b ){
y=a+b;
return y
}//end addition method
}//end class
In the above class, the addition method takes an argument of two integer whole numbers
adds both numbers and returns that value as y=7.
My question is, is it possible to work to re-use y equalling to 7 or do I have to recall the entire
method to get the 7 value.
Below is an example of what I mean.
Code:
public class CalculationExample{
//dclare global variable
int y;
public static void main(String[] args){
addition(4, 3);
System.out.print(y); //is it correct that this line prints 7 or does y only obtain a value
when it is beign called in a method form.
}//end main
public int addition( int a, int b ){
y=a+b;
return y
}//end addition method
}//end class
I'm just trying to figure if after the addition method is run would y obtain the value seven and store it
or if I wanna pull back y as 7 I need to re-enter the entire addition method.
Hope I made myself clear.