Results 1 to 10 of 10
- 11-29-2011, 07:35 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 5
- Rep Power
- 0
java.util.IllegalFormatConversionException error
I have written the following code for a java class. I am currently getting the following error. Any ideas as to what is causing this. I am guessing after I specify a format I cant add more information to the print line. For an easier method i originally made it into 2 print statements, but wanted to know if it would work in one. This is in reference to lines 16 and 17.
Thanks,
Java Code:Feet Meters Meters Feet 1.0 Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.String at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source) at java.util.Formatter$FormatSpecifier.printFloat(Unknown Source) at java.util.Formatter$FormatSpecifier.print(Unknown Source) at java.util.Formatter.format(Unknown Source) at java.io.PrintStream.format(Unknown Source) at java.io.PrintStream.printf(Unknown Source) at ConversionBetweenFeetAndMeters.main(ConversionBetweenFeetAndMeters.java:12)
Java Code:public class ConversionBetweenFeetAndMeters { public static void main(String[] args) { //Assign Variables double meter = 0, foot = 0, footCount, meterCount; // Display Header System.out.println("Feet\tMeters\tMeters\tFeet"); // Create Loop for (footCount = 1, meterCount = 20; footCount <= 10 && meterCount <= 65; footCount++, meterCount = meterCount + 5) { foot = meterToFoot(meterCount); meter = footToMeter(footCount); System.out.printf("\n" + footCount + "\t" + "%.3f", meter + "\t" + meterCount + "\t" + "%.3f", foot); //System.out.printf("\t" + meterCount + "\t" + "%.3f", foot); } } // Calculate Feet To Meters public static double footToMeter(double foot) { return 0.305 * foot; } // Calculate Meters To Feet public static double meterToFoot(double meter) { return meter / 0.305; } }
- 11-29-2011, 08:51 PM #2
Re: java.util.IllegalFormatConversionException error
Look at the API doc for the printf() method. I don't think you are using it correctly.
If you have questions about what the doc says, copy the doc here with your questions.
- 11-29-2011, 09:24 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 5
- Rep Power
- 0
Re: java.util.IllegalFormatConversionException error
What the code is supposed to do is .
This code acheives that affect, but I was just hoping lines 21 and 22 could be combined somehow to take one less line.Java Code:Feet Meters Meters Feet 1.0 0.305 20.0 65.574 2.0 0.610 25.0 81.967 3.0 0.915 30.0 98.361 4.0 1.220 35.0 114.754 5.0 1.525 40.0 131.148 6.0 1.830 45.0 147.541 7.0 2.135 50.0 163.934 8.0 2.440 55.0 180.328 9.0 2.745 60.0 196.721 10.0 3.050 65.0 213.115
Java Code:public class ConversionBetweenFeetAndMeters { public static void main(String[] args) { // Assign Variables double meter = 0, foot = 0, footCount, meterCount; // Display Header System.out.println("Feet\tMeters\tMeters\tFeet"); // Create Loop for (footCount = 1, meterCount = 20; footCount <= 10 && meterCount <= 65; footCount++, meterCount = meterCount + 5) { // Receive returned formulas from Methods and calculate foot = meterToFoot(meterCount); meter = footToMeter(footCount); System.out.printf("\n" + footCount + "\t" + "%.3f", meter); System.out.printf("\t" + meterCount + "\t" + "%.3f", foot); } } // Calculate Feet To Meters public static double footToMeter(double foot) { return 0.305 * foot; } // Calculate Meters To Feet public static double meterToFoot(double meter) { return meter / 0.305; } }Last edited by cartotech81; 11-29-2011 at 09:27 PM.
- 11-29-2011, 09:29 PM #4
Re: java.util.IllegalFormatConversionException error
That is absolutely not important. It's Not worth the effort.somehow to take one less line.
Did you read the API doc for the printf method to see what was wrong with your previous code?
- 11-29-2011, 09:33 PM #5
Member
- Join Date
- Nov 2011
- Posts
- 5
- Rep Power
- 0
Re: java.util.IllegalFormatConversionException error
Were can I find the API Doc. I am using eclipse.
- 11-29-2011, 09:36 PM #6
Re: java.util.IllegalFormatConversionException error
Go to this site and Find the name of the class in the lower left.
The doc for the class will show in the main window.
Scroll down to the method you want to read about.
Java Platform SE 6
- 11-29-2011, 09:38 PM #7
Member
- Join Date
- Nov 2011
- Posts
- 5
- Rep Power
- 0
Re: java.util.IllegalFormatConversionException error
Thanks for the help. Just a beginner here. Think they would mention that website somewhere in the college course book.
- 11-29-2011, 09:51 PM #8
Re: java.util.IllegalFormatConversionException error
That website is "THE WEB SITE" for java. You should save the API link. I use it dozens of times a day.
- 11-29-2011, 09:57 PM #9
Member
- Join Date
- Nov 2011
- Posts
- 5
- Rep Power
- 0
Re: java.util.IllegalFormatConversionException error
Got it bookmarked. Just want to say thank you again. I have gotten to where i can write the basics of java code for a program pretty quickly. Now I am trying to learn how to clean it up a bit more each class. Before today I actually had to "for" loops because I did not know you can have a for loop with multiple conditions.
It realyl is sites like this and helpful people that really get people to stay working on a programming language. If you were stuck to a college course a lot of people would get burnt out and give up completely.
- 11-29-2011, 10:01 PM #10
Similar Threads
-
Weird error with FileHandler, java.util.logging.FileHandler
By nmvictor in forum New To JavaReplies: 2Last Post: 03-09-2010, 08:18 AM -
Jre upgrade Issue :java.util.zip.ZipException: error in opening zip file
By selvakumar.velmurugesan in forum New To JavaReplies: 0Last Post: 10-27-2009, 05:20 AM -
error reading filejava.util.No SuchElementException
By mora in forum JCreatorReplies: 0Last Post: 03-30-2009, 07:35 PM -
java.util.UnknownFormatConversionException error
By rosh72851 in forum Advanced JavaReplies: 7Last Post: 10-09-2008, 04:15 AM -
java.util
By Java Tutorial in forum Java TutorialReplies: 1Last Post: 02-07-2008, 01:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks