package chap1;

import java.io.BufferedReader;
import java.io.FileReader;

public class t1127 {
public static void main(String args[]) throws Exception {
 BufferedReader fr = new BufferedReader(new FileReader("data.txt"));
 String number="4020Q090",name="李依靜";
  
 String str = null;

   
 
 while((str=fr.readLine()) !=null){
     System.out.println(str);

 

 }}}

 

---

 

package chap1;

import java.io.BufferedReader;
import java.io.FileReader;

public class t1127 {
public static void main(String args[]) throws Exception {
 BufferedReader fr = new BufferedReader(new FileReader("data.txt"));
 String number="4020Q090",name="李依靜";
  
 String str = null;
 int num;
   
 
 while((str=fr.readLine()) !=null){
  
  
  num = str.charAt(0);
  System.out.println(num);

 

 }}}

--- 暫存備檔

 

package chap1;

import java.io.BufferedReader;
import java.io.FileReader;

public class t1127 {
public static void main(String args[]) throws Exception {
 BufferedReader fr = new BufferedReader(new FileReader("data.txt"));
 String number="4020Q090",name="李依靜";
  
 String str = null;
 int num =0 , sum=0 ;
   
 while((str=fr.readLine()) != null){
  
 for (int i=0;i<str.length();i++){
  if (str.charAt(i)  !='+'){
  
   // Array Index out of Bounds Exception
   //  陣列  索引值   超過    界限      例外
   num = num*10 + str.charAt(i)-48; 
 }
 
 else{

   sum = sum +num ; 
   num=0;
 }
 }
  System.out.println(sum);
 
 }}
 }
 
 

 

 

 

 

 

 

玥君 發表在 痞客邦 PIXNET 留言(0) 人氣()