【发布时间】:2016-03-23 18:41:25
【问题描述】:
所以当我编译和运行应用程序时,我得到整数的提示,然后什么都没有。我是否没有正确地将整数发送到方法 multiplynumbers():?
import java.util.Scanner;
public class MultiplyNVRM2
{
private static int one=0;
private static int two=0;
private static int product =one * two;
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
System.out.printf("%nPlease enter an integer: ");
one = input.nextInt();
System.out.printf("%nPlease enter another integer: ");
two = input.nextInt();
input.nextLine();
multiplyNumbers();
}//end main()
public static int mulitplyNumbers()
{
product = one * two;
System.out.printf("%n%d * %d = %d", int one, int two, product);
}//end multiplyingNumbers
}
【问题讨论】:
-
这个
System.out.printf("%n%d * %d = %d", int one, int two, product);不是合法代码。 -
另外,您没有向函数“发送”任何整数。您只是调用一个使用变量一和二的值的函数。
-
我建议你 a) 编译代码,b) 用你的代码格式化程序整理代码,c) 我建议你将值作为参数传递,而不是静态字段。
-
任何标准的 IDE 像 Eclipse 都会立即给你写 System.out.printf(); 的错误;
标签: java methods parameters integer