Facebook
From Adrian Pietrzak, 5 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 199
  1. package lab6;
  2.  
  3. import java.io.*;
  4. import java.nio.file.Path;
  5. import java.nio.file.Paths;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import java.util.Scanner;
  9.  
  10. public class Zad2 {
  11.  
  12.         static Scanner scanner = null;
  13.         static int[][] arr = new int[10][10];
  14.         static String[] s = new String[10];
  15.         static List<String> slist = new ArrayList<String>();
  16.  
  17.         static String str2 = null;
  18.  
  19.         public static void main(String[] args) {
  20.                 // open();
  21.                 openLines();
  22.                 show();
  23.  
  24.         }
  25.  
  26.         static void open() {
  27.                 Path filePath = Paths.get("calculator_data.txt");
  28.                 String str = null;
  29.                 int x = 0;
  30.  
  31.                 try {
  32.                         scanner = new Scanner(filePath);
  33.                         str2 = scanner.nextLine();
  34.  
  35.                         scanner.reset();
  36.                         scanner = new Scanner(filePath);
  37.  
  38.                         while (scanner.hasNext()) {
  39.                                 str = scanner.next();
  40.                                 if (!(x > 1 && (str.charAt(0) == '+' || str.charAt(0) == '-' || str.charAt(0) == '*' || str.charAt(0) == '/'))) {
  41.                                         s[x] = str;
  42.                                         x++;
  43.                                 }
  44.                         }
  45.                 } catch (IOException e) {
  46.                         System.out.println("IOException!!!!!!!!");
  47.                 }
  48.  
  49.         }
  50.  
  51.         static void openLines() {
  52.                 Path filePath = Paths.get("calculator_data.txt");
  53.                 String str;
  54.                 // int x = 0;
  55.                 try {
  56.                         scanner = new Scanner(filePath);
  57.                         while (scanner.hasNext()) {
  58.                                 str = scanner.nextLine();
  59.                                 // s[x] = str;
  60.                                 slist.add(str);
  61.                                 // x++;
  62.                         }
  63.                 } catch (IOException e) {
  64.                         System.out.println("IOException!!!!!!!!");
  65.                 }
  66.         }
  67.  
  68.         static void show() {
  69.                 // for (int i = 0; i < s.length; i++) {
  70.                 // if (s[i] != null)
  71.                 // System.out.println(s[i]);
  72.                 // }
  73.  
  74.                 slist.forEach(System.out::println);
  75.  
  76.                 // System.out.println(str2);
  77.  
  78.         }
  79.  
  80. }