我正在 Eclipse IDE 中学习 Java。我无法弄清楚如何让 printf 工作或定义它。我已经检查过,我正在为我拥有的 Java 使用正确的编译器,即 1.6。这是我得到的错误:
Syntax error on token ".", ; expected
The method printf(String, int) is undefined for the type Addition
该程序:
// Fig 2.7: Addition.java
// Addition program that displays the sum of two numbers.
import java.util.Scanner; // program uses class Scanner
public class Addition
{
// main method begins execution of Java application
public static void main( String[] args )
{
// create a Scanner to obtain input from the command window
Scanner input = new Scanner( System.in );
int number1; // first number to add
int number2; // second number to add
int sum; // sum of number1 and number2
System.out.print( "Enter first integer: "); // prompt
number1 = input.nextInt(); // read first number from user
System.out.print( "Enter second integer: "); // prompt
number2 = input.nextInt(); // read second number from user
sum = number1 + number2; // add numbers, then store total in sum
System out.println( "Sum is %d\n", sum ); // display sum
} // end method main
} // end class Addition
我已经尝试过 Eclipse 的自动修复,但它仍然会给我令牌“。”的错误。