私は、ユーザーが6つの温度測定値を入力し、次に次のいずれかを入力できるプログラムを作成しています。
- 最高の元の値を返す+摂氏バージョン
- 元の値+摂氏バージョンへの変換を返します。
配列値が設定されるコードは次のとおりです。
System.out.print( "Enter Temperature:\t"); //Get the count...
Temp = LocalInput.nextInt();
WeatherSpots[K].CatchCount = Temp;
私が受け取るエラーメッセージはこれです
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)"
私はまた私に問題を与える正確なフレーズを見つけました:
String.format("%.2d", (WeatherSpots[K].CatchCount - 32) * 5 / 9)"
正しい指定子がない場合にエラーが発生することはわかっていますが"%._"
、すべての変数と配列がintにあるため、dが機能しているはずです。
残りのコードは次のとおりです。
これは私が最初の配列を設定する方法です:
private static WeatherLocation[] WeatherSpots = new WeatherLocation[6];"
これは、後の配列が使用するクラスです
public class WeatherLocations extends WeatherLocation {
public String LocationID;
public Integer CatchCount;"
arrays = WeatherSpots.LoccationID/Catchcount"
ここで、catchcount
アレイはユーザー入力温度で設定されます
int K;
for(K = 0 ; K < 6 ; K++){
System.out.print( "Enter Temperature:\t");
Temp = LocalInput.nextInt();
WeatherSpots[K].CatchCount = Temp;
これが私WeatherSpots[K].catchcount
が摂氏に変換するために値を 呼び出そうとする方法です
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));
私の配列と変数が使用するのに適切なタイプである場合、エラーの原因は何string.format
ですか?