Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8126959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:20:43+00:00 2026-06-06T07:20:43+00:00

I’m writing a program that lets the user input 6 temperature readings, and then

  • 0

I’m writing a program that lets the user input 6 temperature readings, and then either

  1. return the highest original values +celcius version
  2. return the original values + conversion into the celsius version.

the code where the arrays values are set is here:

System.out.print( "Enter Temperature:\t");   //Get the count...
        Temp = LocalInput.nextInt();
        WeatherSpots[K].CatchCount = Temp;

the error message that i get is this

java.util.IllegalFormatConversionException: f != java.lang.Integer
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.util.Formatter.format(Unknown Source)
at java.lang.String.format(Unknown Source)
at p2list.WeeklyReport(p2list.java:102)
at p2list.main(p2list.java:33)"

i’ve also found the exact phrase that gives me trouble:

String.format("%.2d", (WeatherSpots[K].CatchCount - 32) * 5 / 9)"

i know that the error happens when my "%._" doesn’t have the right specifier, but all of my variables and arrays are in int, so d should be working

here’s the rest of the code:

This is how i set the 1st array:

private static  WeatherLocation[] WeatherSpots = new WeatherLocation[6];"

This is the class that later arrays use

public class WeatherLocations extends WeatherLocation {
    public String LocationID;
    public Integer CatchCount;"

    arrays = WeatherSpots.LoccationID/Catchcount"

Here’s where the catchcount array is set with the user input temperatures

int K;
for(K = 0 ; K < 6 ; K++){
    System.out.print( "Enter Temperature:\t");
    Temp = LocalInput.nextInt();
    WeatherSpots[K].CatchCount = Temp;

Here’s the method where i try to call on the WeatherSpots[K].catchcount values to convert to celcius

int K= 0;
for(K = 0 ; K < 6 ; K++){
    System.out.println( "" + WeatherSpots[K].LocationID +"\t\t" + WeatherSpots[K].CatchCount + "\t\t" + String.format("%.2f", (WeatherSpots[K].CatchCount - 32) * 5 / 9));

What would be causing the error, if my arrays and variables are the proper types for using string.format?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:20:45+00:00Added an answer on June 6, 2026 at 7:20 am

    In

    String.format("%.2f", (WeatherSpots[K].CatchCount - 32) * 5 / 9)
    

    you are trying to print an int with a format for doubles or floats. That causes the IllegalFormatConversionException: f != java.lang.Integer. Since the integer division truncates anyway, it isn’t very useful to print an integer with two places after the decimal point. Just divide by the floating point number 9.0 instead of the int 9 to get a floating point number that you can format with %.2f.

    In your

    String.format("%.2d", (WeatherSpots[K].CatchCount - 32) * 5 / 9)
    

    the format %.2d is invalid since it doesn’t make sense to print integers with places after the decimal point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.