Advertisement
Niloy007

FinalSampleProb4

Dec 14th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4.  
  5. class ListOfNumbers {
  6.     private int[] list;
  7.     private static final int SIZE = 10;
  8.  
  9.     public ListOfNumbers() {
  10.         list = new int[SIZE];
  11.         for(int i = 0; i < SIZE; i++)
  12.         list[i] = i;
  13.     }
  14.  
  15.     public void readList() {
  16.         FileReader reader;
  17.         BufferedReader bufferedReader;
  18.         try {
  19.             reader = new FileReader("src/SampleSolution/file1.txt");
  20.             bufferedReader = new BufferedReader(reader);
  21.  
  22.             String a;
  23.             while((a = bufferedReader.readLine()) != null) {
  24.                 int i = 0;
  25.  
  26.                 String[] array = a.split(" ");
  27.                 for(String b : array) {
  28.                     list[i++] = Integer.parseInt(b);
  29.                 }
  30.             }
  31.  
  32.             for(int i : list) {
  33.                 System.out.print(i + " ");
  34.             }
  35.  
  36.         } catch (IOException e) {
  37.             System.out.println(e.getMessage());
  38.             e.printStackTrace();
  39.         } catch (NumberFormatException e) {
  40.             System.out.println(e.getMessage());
  41.             e.printStackTrace();
  42.         }
  43.     }
  44. }
  45.  
  46. public class FourSolution {
  47.     public static void main(String[] args) {
  48.         new ListOfNumbers().readList();
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement