私は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 から自動修正を試みましたが、それでもトークン "." でエラーが発生します。