Sam*_*Sam 0 java argument-passing
我刚开始研究如何用Java编程语言编写代码.
我遇到了一个问题,告诉我将数字,变量和表达式作为过程调用的参数传递.我遇到的问题是,当我尝试将数字,变量和表达式作为参数传递给过程调用时,我收到错误(我有27个错误).
下面是我的代码,如果有人能指出我的代码有什么问题,我将非常感激.谢谢.
public class test {
// this is the procedure definition
public static int computeCost ( int quantity , int price ) {
return quantity * price;
}
public static void main ( String args[] )
// passing numbers as arguments to the procedure call "cost"
System.out.println ( computeCost ( 7 , 12 ) );
// passing variables as arguments to the procedure call "cost"
int a = 5;
int b = 7;
System.out.println ( computeCost ( a , b ) );
// passing expressions as arguments to the procedure call "cost
System.out.println ( computeCost ( 1 + 2 + 3 + 4, 5 + 6 + 7 + 8 ) );
}
}
Run Code Online (Sandbox Code Playgroud)
我明白了什么是错的.在main(..)方法之后没有左括号.Java中的所有方法都必须用{和包围它们的代码}.
改变这个:
public static void main ( String args[] )
Run Code Online (Sandbox Code Playgroud)
对此:
public static void main ( String args[] ) {
Run Code Online (Sandbox Code Playgroud)
除此之外,你的代码对我来说非常好.
| 归档时间: |
|
| 查看次数: |
207 次 |
| 最近记录: |