Javaで以下の様な二列の数字を他のテキストファイルから別々に読み込み表示したいです。
484954 2814
1036451 3630
1006577 3805
828170 2781
497471 3201
.
.
.
.
.
###発生している問題
以下のように二列の数字が足されて出てきます
File opend 487768 1040081 1010382 830951 500672 749776 . . . . .
初心者なので見よう見まねで書いたのですがよくわかりません。
###コード
package
1 2import java.io.File; 3import java.io.FileNotFoundException; 4import java.util.Scanner; 5 6public class Housing0PE { 7 8 public static void main(String[]arg) { 9 10 // read in the data 11 int priceHome[] = new int[100]; 12 int rpm[] = new int[100]; 13 14 File file = new File ("housingPriceAndRent.txt"); 15 Scanner input = null; 16 17 try { 18 input = new Scanner(file); 19 } catch (FileNotFoundException e) { 20 // file Not found 21 System.out.println("File not found"); 22 e.printStackTrace(); 23 System.exit(0); 24 } 25 26 System.out.println("File opend"); 27 28 int count = 0; 29 while(input.hasNextInt()){ 30 priceHome[count] = input.nextInt(); 31 rpm[count] = input.nextInt(); 32 count++; 33 34 }//end while 35 36 for(int i = 0; i < priceHome.length; i++) { 37 System.out.println(priceHome[i]+rpm[i]); 38 } 39 }//end main 40}//end class 41
回答1件
あなたの回答
tips
プレビュー