gpt4 book ai didi

java - printf 为 "Cannot resolve symbol error"

转载 作者:行者123 更新时间:2023-12-01 17:26:47 24 4
gpt4 key购买 nike

这段代码在编译过程中导致错误...我不知道我做错了什么?

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);
}
}

最佳答案

printf 仅在 1.5 版本中可用,在 1.4.2 中尚不可用。既然您在问(请参阅评论),那么这样做:

for(int i = 0; i < 10; i ++)
{
System.out.println((i + 1) + "\t" + frequency[i]);
}

关于java - printf 为 "Cannot resolve symbol error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14271148/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com