https://qiita.com/hp_kj/items/789a7fb7e922745f8bd9#comment-f22f811bbe75340a3f1b As you pointed out in the comment section, I investigated the formal and actual arguments. Thank you very much!
I learned arguments in the beginning. I thought I could afford it. For example
python
public static void main(String[]args){
int x = 10;
int y = 20;
System.out.println(add(x,y));
}
public static int add(int x,int y){
return x + y;
}
I could understand the above. to the add function x 10 20 of y is included. As a result, 30 is output.
However, I didn't understand when this happened.
python
public static void main(String[]args){
int x = 10;
int y = 20;
System.out.println(add(x,y));
}
public static int add(int a,int b){
return a + b;
}
No, not a and b, I want to put x and y in the add function.
So I studied functions on udemy.
The result is that the function arguments are just entrances. That was the conclusion.
Write an example.
python
public static void main(String[]args){
int x = 10;
int y = 20;
System.out.println(add(x,y));
}
public static int add(int a,int b){
return a + b;
}
First is this code. Disassemble. It's half done.
python
int add(int a,int b){
return a + b;
}
My writing ability is too weak. Further disassemble.
python
int add(int a){
return a;
}
Think about this.
This add function will be named a if you use an int type as an argument. !! This is important.
It is used as a in the add function. It means int a. So, for example
python
public static void main(String[]args){
int x = 10;
int cccc = 20;
System.out.println(add(x,cccc));
}
public static int add(int aaaaaaa,int bbbbbbb){
return aaaaaaa + bbbbbbb;
}
So, whether it's x, y, or cccc, it will return as long as you use the int type.
Even the add function disappeared from the middle, but thank you for reading. I thought I was writing. It's easy to convey videos.
Recommended Posts