Results 1 to 2 of 2
Thread: printf error with int and double
- 09-18-2008, 07:20 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 1
- Rep Power
- 0
printf error with int and double
I have the following problem, I'm trying to print some values in the following format(shown on the following code) but printf doesn't work. when i tried to run the program it gave the following message<<Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int, double)>>
the code :
System.out.printf("%10d%22.4f", dice, average);
where dice is of type int and average is of type double.
The following is the whole program please Help!!
public class DiceAverage {
static final int NUMBER_OF_EXPERIMENTS = 10000;
public static void main(String[] args){
double average;
System.out.println("Total On Dice Average Number of Rolls");
System.out.println("_____________ _______________________");
for(int dice = 2; dice <= 12; dice++ ){
average = AverageRollCount(dice);
System.out.printf("%10d%22.4f", dice, average);
}
}
public static double AverageRollCount( int Roll ){
int RollCountThisExperiment;
int TotalRoll;
double averageRollCount;
TotalRoll = 0;
for(int i = 0; i < NUMBER_OF_EXPERIMENTS; i++){
RollCountThisExperiment = rollFor( Roll );
TotalRoll += RollCountThisExperiment;
}
averageRollCount = ((double)TotalRoll) / NUMBER_OF_EXPERIMENTS;
return averageRollCount;
}
public static int rollFor( int N ){
int die1, die2;
int roll;
int rollCount = 0;
do {
die1 = (int)(Math.random()*6) + 1;
die2 = (int)(Math.random()*6) + 1;
roll = die1 + die2;
rollCount = rollCount++;
}while (roll != N );
return rollCount;
}
}
I use eclipse version:3.4.0
- 09-18-2008, 08:58 PM #2
Please copy the full text of the error message without editting it.
Here's what I get when I execute it using: jre1.6.0_02\bin\java.exe :
Java Code:Total On Dice Average Number of Rolls _____________ _______________________ 2 0.0000 3 0.0000 4 0.0000 5 0.0000 6 0.0000 7 0.0000 8 0.0000 9 0.0000 10 0.0000 11 0.0000 12 0.0000Last edited by Norm; 09-18-2008 at 09:16 PM.
Similar Threads
-
Double Value problem
By sakthivel123 in forum New To JavaReplies: 2Last Post: 07-10-2008, 04:18 PM -
Demonstration of printf() method
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:37 PM -
Calculating sin of a double value
By Java Tip in forum Java TipReplies: 0Last Post: 01-13-2008, 08:13 PM -
printf
By Jack in forum New To JavaReplies: 2Last Post: 07-04-2007, 04:31 AM -
How to round a double?
By Valeriano in forum New To JavaReplies: 1Last Post: 05-31-2007, 03:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks