Advertisement
KuoHsiangYu

ShowPrice100.java

Feb 8th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. //Java程式
  2. /*
  3.  * To change this license header, choose License Headers in Project Properties.
  4.  * To change this template file, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. package com.sample;
  8.  
  9. import java.io.File;
  10. import java.util.Scanner;
  11. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13.  
  14. /**
  15.  *
  16.  * @author 郭翔宇
  17.  */
  18. public class ShowPrice100 {
  19.  
  20.     /**
  21.      * @param args the command line arguments
  22.      */
  23.     public static void main(String[] args) {
  24.         // TODO code application logic here
  25.        
  26.         try {
  27.             int count = 0;
  28.             File file = new File("data.txt");
  29.             Scanner scanner = new Scanner(file);
  30.             String input = "";
  31.             while (scanner.hasNext()) {
  32.                 count = count + 1;
  33.                 System.out.printf("%04d.\t", count);
  34.                 input = scanner.nextLine();
  35.                 String input2[] = input.split(" ");
  36.                 for (int i = 0; i < 5; i++) {
  37.                     System.out.printf("%.0f\t", Double.parseDouble(input2[i]));
  38.                 }
  39.                 System.out.printf("\n");
  40.             }
  41.             scanner.close();
  42.         } catch (Exception ex) {
  43.             System.out.println(ex);
  44.             Logger.getLogger(ShowPrice100.class.getName()).log(Level.SEVERE, null, ex);
  45.         }
  46.     }
  47.  
  48. }
  49.  
  50. /*
  51. data.txt
  52.  
  53. 200306030 37.1 37.4 36.92 37.08
  54. 20030701 37.09 38.1 37.09 38.05
  55. 20030702 38.17 38.82 38.1 38.69
  56. 20030703 40.6 40.6 38.81 39
  57. 20030704 39.1 39.26 38.75 39.26
  58. 201901018 75.75 76.1 75.4 75.95
  59. 201901021 76.35 76.7 76.25 76.5
  60. 201901021 76.35 76.7 76.25 76.5
  61. 201901021 76.35 76.7 76.25 76.5
  62. 201901021 76.35 76.7 76.25 76.5
  63. */
  64.  
  65. /*
  66. Mion He
  67. 5 小時
  68. 請教各位前輩,我用java 8在class建立了二為陣列:3867列,5欄,可是為什麼印出陣列長度卻只有1002?
  69. 跑迴圈時用length只能印出一部分資料,設定長度時也只印一部分且出現C:\\Users\\user\\AppData\\Local\\NetBeans\\Cache\\8.2\\executor-snippets\\run.xml:53: Java returned: 1。
  70. 想請問前輩們這是發生什麼事?
  71. https://www.facebook.com/groups/1403852566495675/permalink/2265069293707327/
  72.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement