Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package mid2;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.PrintWriter;
- public class Olympic1 {
- public int sum1,sum2,sum3 ;
- public int [] a = new int [5];
- BufferedReader bufferedReader = null;
- String line = "";
- public void read(){
- try{
- bufferedReader = new BufferedReader(new FileReader("C:\\Users\\common.LAB8PC-03\\Documents\\NetBeansProjects\\Mid2\\olympic.txt"));
- int i = 0;
- while((line = bufferedReader.readLine()) != null){
- String [] s = line.split(" ");
- System.out.println(s[0]+"\t"+s[1]+"\t"+s[2]+"\t"+s[3]);
- int gold = Integer.parseInt(s[1]);
- int silver = Integer.parseInt(s[2]);
- int bronze = Integer.parseInt(s[3]);
- int sum = gold + silver + bronze ;
- System.out.println("Sum of medals: "+sum+"\n");
- a[i] = sum;
- i++;
- }
- }
- catch(Exception e){
- e.printStackTrace();
- }
- }
- public void write(){
- try{
- PrintWriter pw = new PrintWriter("processed.txt","UTF-8");
- for(int i = 0; i<5;i++){
- pw.println("Summaion of medals: "+a[i]);
- }
- pw.close();
- }
- catch(Exception e){
- e.printStackTrace();
- }
- }
- public static void main(String [] args){
- Olympic1 olympic = new Olympic1();
- olympic.read();
- olympic.write();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement