想改进这个问题吗?通过编辑这篇文章添加详细信息并澄清问题。
package helloWorld;
class squaredValue {
static int valueOf (int x) {
return x;
int x = 10;
System.out.println("Square of "+ x + " is: "+(x*x));
}
public static void main(String[] args) {
valueOf();
}
}
创建一个简单的 Java 程序,该程序使用一个参数实现方法,该参数将返回变量的平方值。
示例输出:x的值是:10,10的平方值是:100
您走在正确的轨道上。只需返回值而不是打印它:
return x * x