此代码在编译期间导致错误...我不知道我做错了什么?
CoinFlippingContest.java:27: cannot resolve symbol
symbol : method printf (java.lang.String,int,int)
location: class java.io.PrintStream
System.out.printf(" %d \t %d",(i+1),frequency[i]);
^
1 error
一切都必须在 Java 1.4.2 中。这是代码:
//IMPORT JAVA UTILITIES AND IO
import java.io.*;
import java.util.*;
//DEFINE CLASS
public class CoinFlippingContest
{
public static void main( String args[] )
{
//GENERATES RANDOM NUMBER
Random randomNumbers = new Random();
int[] frequency = new int[10];
for(int i=0; i<10; i++)
frequency[i]=0;
int number;
//RESULTS FOR 6000
for ( int col = 1; col <= 6000; col++ )
{
number = 1 + randomNumbers.nextInt( 10 );
frequency[number]++;
}
//DISPLAY THE HEADINGS
System.out.println( "number\tFrequency" );
for(int i=0; i<10; i++)
System.out.printf(" %d \t %d",(i+1),frequency[i]);
//NUMBER OF HEADS AND TAILS IN TOTAL
int even = 0, odd = 0;
for(int i=0; i<10; i++)
{
if(i%2==0)
odd +=frequency[i];
else even += frequency[i];
}
//OUTPUT NUMBER OF HEADS AND TAILS EVEN AND ODDS
System.out.println("\nheads: "+even+"\ntails: "+odd);
}
}