我正在为学校做作业,并摆弄一些不同类型的循环,即 for 循环...我很好奇它接受的项目是否被视为参数或参数...以及实际的是什么两者有何区别?
for(初始化;条件;递增/递减){ 声明 }
最佳答案
如 Java Docs 中所述:
Parameters refers to the list of variables in a method declaration. Arguments are the actual values that are passed in when the method is invoked. When you invoke a method, the arguments used must match the declaration's parameters in type and order.
例如moveCircle()
方法在声明中有 3 个参数,例如:circle
、deltaX
、deltaY
>.
public void moveCircle(Circle circle, int deltaX, int deltaY) {
//...
}
例如moveCircle()
方法被调用并有 3 个参数:
moveCircle(myCircle, 23, 56)
如果我们谈论循环,那么我们有 the general form of the for statement像:
for (initialization; termination;
increment) {
statement(s)
}
在哪里:
- 初始化表达式初始化循环;它被执行了 当循环开始时一次。
- 当终止表达式求值时 为 false,循环终止。
- 调用增量表达式 每次循环迭代之后;这是完全可以接受的 此表达式可增加或减少一个值。
关于java - 参数和参数有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60140236/