Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. /**
  2.  *
  3.  *  @author Wieczorek Krzysztof S15877
  4.  *
  5.  */
  6.  
  7. package zad3;
  8.  
  9. import java.io.File;
  10. import java.io.FileNotFoundException;
  11. import java.util.ArrayList;
  12. import java.util.Scanner;
  13. import java.util.regex.Matcher;
  14. import java.util.regex.Pattern;
  15.  
  16. public class Main {
  17.  
  18.   public static void main(String[] args) throws FileNotFoundException {
  19.     String fname = System.getProperty("user.home") + "/tab.txt";      
  20.     try{
  21.     ArrayList list = new ArrayList();
  22.     File file = new File(fname);
  23.     Scanner scan = new Scanner(file);
  24.     Pattern p1 = Pattern.compile("[^\\s][-]?[\\d]*");
  25.     while(scan.hasNextLine()){
  26.         Matcher m1 = p1.matcher(scan.nextLine());
  27.      while(m1.find()){
  28.          list.add(m1.group());
  29.      }
  30.     }
  31.    
  32.     int[] tab = new int[list.size()];
  33.     for(int i =0; i < list.size(); i++){
  34.         int a = Integer.valueOf((String) list.get(i));
  35.         tab[i]= a;
  36.     }
  37.     for(int i = 0; i< tab.length; i++){
  38.         System.out.print(tab[i]+ " ");
  39.     }
  40.     int x = 0;
  41.     for(int i = 0; i < tab.length; i++){
  42.         if(tab[i]>x){
  43.             x = tab[i];
  44.         }
  45.        
  46.     }
  47.     System.out.println("\n" + x);
  48.    
  49.     for(int i = 0; i > tab.length ; i++){
  50.         if(tab[i] == x){
  51.             System.out.println(i);
  52.     }else{
  53.         System.out.println("nie");
  54.     }
  55.     }
  56.   }catch(FileNotFoundException e) {
  57.       System.out.println("***");
  58.   }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement