以下のコードを実行すると次のようなエラーが出ます。
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); //処理をカウント int cnt = 0; int paramNum = 0; int usrNum = 0; int rankNum = 0; float keisu[] = null; int rank[]; while(line != null){ //一行ずつ読み取る line = br.readLine(); if(cnt == 0){ //1行目(期待される値 3 41 5) //文字を分割 String[] temp = line.split(" ", 0); paramNum = Integer.parseInt(temp[0]); usrNum = Integer.parseInt(temp[1]); rankNum = Integer.parseInt(temp[2]); rank = new int[rankNum]; }else if(cnt == 1){ //2行目(期待される値 1.5 1.2 0.2) keisu = new float[paramNum]; String[] temp2 = line.split(" ", 0); for(int i=0; i <= paramNum;i++){ keisu[i] = Float.parseFloat(temp2[i]); } }else{ //3行目以降(期待される値 621 641 100) int item[] = new int[paramNum]; int score = 0; String[] temp3 = line.split(" ", 0); for(int i=0; i <= paramNum;i++){ item[i] = Integer.parseInt(temp3[i]); score += item[i] * keisu[i]; } System.out.println(String.valueOf(score)); } cnt++; } br.close(); } }
実行すると次のようなエラーが出ます。
Exception in thread "main" java.lang.NumberFormatException: For input string: "1.5"
javaを初めて間もないため、調べてみたのですが改善点が分かりません
どなたかご教授願えないでしょうか
よろしくお願い致します。
何行目で出ていますか?エラーの全てを記載してください。

回答2件
あなたの回答
tips
プレビュー