Advertisement
Niloy007

Shawon's assignment

May 22nd, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. package Assignment;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7.  
  8. public class main {
  9.     public static void main(String[] args) {
  10.         try {
  11.             BufferedReader reader = new BufferedReader(new FileReader("/Users/niloykumarkundu/Desktop/Socket/src/Assignment/input.txt"));
  12.             int[] arr = new int[100];
  13.             String input;
  14.             int i = 0;
  15.             while((input = reader.readLine()) != null) {
  16.                 String[] list = input.split(",");
  17.                 for(String x : list) {
  18.                     arr[i++] = Integer.parseInt(x);
  19.                 }
  20.             }
  21.  
  22.             for(int j = 0; j < i; j++) {
  23.                 for(int k = j; k < i; k++) {
  24.                     if(arr[j] < arr[k]) {
  25.                         int temp = arr[j];
  26.                         arr[j] = arr[k];
  27.                         arr[k] = temp;
  28.                     }
  29.                 }
  30.             }
  31.  
  32.             for(int j = 0; j < i; j++) {
  33.                 if(j == i - 1) {
  34.                     System.out.println(arr[j]);
  35.                 } else {
  36.                     System.out.print(arr[j] + ",");
  37.                 }
  38.             }
  39.         } catch (FileNotFoundException e) {
  40.             e.printStackTrace();
  41.         } catch (IOException e) {
  42.             e.printStackTrace();
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement