Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package FileLecture;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileReader;
- import java.io.FileWriter;
- public class Olympics {
- public static void main(String[] args) {
- int j;
- boolean flag = true;
- int temp;
- String temp1;
- int[] A = new int[4];
- String[] string = new String[4];
- int[] num = new int[4];
- try {
- BufferedReader reader1 = new BufferedReader(new FileReader("olympics.txt"));
- BufferedWriter reader2 = new BufferedWriter(new FileWriter("processed.txt", true));
- String line;
- for(int i=0;i<4;i++){
- line=reader1.readLine();
- if(line==null)
- break;
- String[] splitted = line.split(",");
- for(String x: splitted){
- if(A[i]==0){
- string[i] = x;
- A[i]++;
- }
- else{
- num[i] += Integer.parseInt(x);
- }
- }
- }
- while ( flag =false ){
- for( j=0; j < num.length -1; j++ )
- {
- if ( num[ j ] < num[j+1] )
- {
- temp = num[ j ];
- temp1 = string[j];
- num[ j ] = num[ j+1 ];
- string[j] = string[j+1];
- num[ j+1 ] = temp;
- string[j+1] = temp1;
- flag = true;
- }
- }
- }
- for(int p=0;p<4;p++){
- reader2.write(string[p]+" "+num[p]);
- reader2.newLine();
- reader2.flush();
- }
- reader2.close();
- } catch (Exception ex) {
- System.out.println(ex);
- }
- }
- }
- /*/*import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileReader;
- import java.io.FileWriter;
- public class Olympics {
- public static void main(String... args)
- {
- try {
- BufferedReader reader = new BufferedReader(new FileReader("olympics.txt"));
- String line;
- long total =0;
- while(true)
- {
- line=reader.readLine();
- if(line == null)
- break;
- int k = Integer.parseInt(line);
- String [] splitted= line.split(",");
- for(String x: splitted)
- System.out.println(x);
- //total = total + Integer.parseInt();
- System.out.println(k);
- }
- BufferedWriter writer =
- new BufferedWriter(new FileWriter("processed.txt"));
- writer.write("Hello World");
- writer.flush();
- } catch (Exception ex) {
- System.out.println(ex);
- }
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement