package chap1;

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

public class t1113 {
 public static void main(String args[]) throws Exception {
  BufferedReader fr = new BufferedReader(new FileReader("data.txt"));
  int data[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  String str = null;
while((str=fr.readLine()) != null){
 System.out.println(str);
}

 }}

 

---

 

package chap1;

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

public class t1113 {
 public static void main(String args[]) throws Exception {
  BufferedReader fr = new BufferedReader(new FileReader("data.txt"));
  int data[]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  int i=0;
  int total = 0;
  //int data[] = new int[100];
  
  String str = null;
while((str=fr.readLine()) != null){
 System.out.println(str);
  data[i]=Integer.parseInt(str);
  System.out.println("data["+i+"]="+data[i]);
  i++;
}

 

---

 

 

package chap1;

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

public class t1113 {
 public static void main(String args[]) throws Exception {
  BufferedReader fr = new BufferedReader(new FileReader("data.txt"));
  int data[]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  int i=0,sum=0;
  //int data[] = new int[100];
  
  String str = null;
while((str=fr.readLine()) != null){
 System.out.println(str);
  data[i]=Integer.parseInt(str);
  System.out.println("data["+i+"]="+data[i]);
  i++;
}

for ( i=0; i<20;i++){
 sum = sum+data[i];
 System.out.println("data["+i+"]="+data[i]+"\t sum="+sum);
 }}}

 

---

 

 

package chap1;

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

public class t1113 {
 public static void main(String args[]) throws Exception {
  BufferedReader fr = new BufferedReader(new FileReader("data1.txt"));
  
  int data[] = new int[100];
  //int data[] = new int[100];
  String str = null;
  
  while((str=fr.readLine()) != null){
   System.out.println(str);

 for(int i=0;i<7;i++){
  System.out.print(str.charAt(i));
 }
  }

 }}
 

---

 

package chap1;

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

public class t1113 {
 public static void main(String args[]) throws Exception {
  BufferedReader fr = new BufferedReader(new FileReader("data1.txt"));
  
  int data[] = new int[100];
  //int data[] = new int[100];
  String str = null;
  
  while((str=fr.readLine()) != null){
   System.out.println(str);

 for(int i=0;i<7;i++){
  if(str.charAt(i) !='+'){ //為了去掉+號
  System.out.print(str.charAt(i));
 }
  }
  }}}

 ---

 

package chap1;

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

public class t1113 {
 public static void main(String args[]) throws Exception {
  BufferedReader fr = new BufferedReader(new FileReader("data1.txt"));
  
  //int data[] = new int[100];
  String str = null;
  int num=0;
  
  while((str=fr.readLine()) != null){
   System.out.println(str);

 for(int i=0;i<7;i++){
  if(str.charAt(i) !='+'){ //為了去掉+號
   num=str.charAt(i)-48;//ASCII碼
   System.out.println(num+"\t"+str.charAt(i));
 }
  }
  }}}
 

---

 

package chap1;

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

public class t1113 {
 public static void main(String args[]) throws Exception {
  BufferedReader fr = new BufferedReader(new FileReader("data1.txt"));
  
  //int data[] = new int[100];
  String str = null;
  int num=0;
  int sum=0;
  
while((str=fr.readLine()) != null){
   System.out.println(str);

for(int i=0;i<7;i++){
 if(str.charAt(i) !='+'){ //為了去掉+號
   num=num*10+str.charAt(i)-48;
  }
 else{
   System.out.println("num = "+num);
   num=0;//沒輸出25 是因為25後方沒有+號
  }
}
 //for END
   System.out.println("num = "+num);
   
   sum = sum +num;
   System.out.println("sum= "+sum);
}//while迴圈
//main() END
//class END
   sum = sum+num;num=0;
   }
 }
   

 ---

package chap1;

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

public class t1113 {
 public static void main(String args[]) throws Exception {
  BufferedReader fr = new BufferedReader(new FileReader("data1.txt"));
  
  //int data[] = new int[100];
  String str = null;
  int num=0;
  int sum=0;
  
while((str=fr.readLine()) != null){
   System.out.println(str);

for(int i=0;i<7;i++){
 if(str.charAt(i) !='+'){ //為了去掉+號
   num=num*10+str.charAt(i)-48;
  }
 else{
   System.out.println("num = "+num);
   sum = sum +num;
   num=0;//沒輸出25 是因為25後方沒有+號
  }
}
 //for END

   sum = sum +num;
   System.out.println("num = "+num);
   System.out.println("sum= "+sum);
}//while迴圈
//main() END
//class END
   sum = sum+num;num=0;
   }
 }
   
 

 

 

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