Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. //package profesjonal; Bartlomiej Wiewiora
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5. import java.io.BufferedReader;
  6. import java.io.File;
  7. import java.io.FileInputStream;
  8. import java.io.IOException;
  9. import java.io.InputStreamReader;
  10. import java.io.UnsupportedEncodingException;
  11.        
  12.  
  13. public class Profesjonal {
  14.  
  15.    
  16.     public static void main(String[] args) {
  17.         File fileDir = new File("opis.txt");
  18.            
  19.         try{
  20.         BufferedReader in = new BufferedReader(
  21.            new InputStreamReader(
  22.                       new FileInputStream(fileDir), "UTF8"));
  23.                
  24.         String str;
  25.         int maxLength = 0;
  26.  
  27.                 String najdl = "";
  28.             while ((str = in.readLine()) != null) {
  29.                 String [] tab = str.split("[ .,\\-]");
  30.                
  31.                     for(int d = 0; d < tab.length; d++){
  32.                              if (tab[d].length() > maxLength) {
  33.                             maxLength = tab[d].length();
  34.                             najdl = tab[d];
  35.           }
  36.                         }
  37.                        
  38.                    
  39.                 }
  40.        
  41.                 System.out.println(najdl);
  42.                
  43.                 in.close();
  44.         }
  45.        
  46.         catch (UnsupportedEncodingException e)
  47.         {
  48.             System.out.println(e.getMessage());
  49.         }
  50.         catch (IOException e)
  51.         {
  52.             System.out.println(e.getMessage());
  53.         }
  54.         catch (Exception e)
  55.         {
  56.             System.out.println(e.getMessage());
  57.         }
  58.     }
  59.    
  60. }
  61.  
  62.  
  63. ////////////
  64.  
  65.  
  66. //package kolos2; Bartlomiej Wiewiora
  67.  
  68. import java.io.*;
  69. import java.util.*;
  70.  
  71.  
  72.  
  73. public class Kolos2
  74. {
  75.    
  76.     public static void main(String[] args) throws IOException
  77.     {
  78.         ArrayList<Integer> liczby = new ArrayList<Integer>();
  79.         Scanner patrz = new Scanner(System.in);
  80.        
  81.         String nr = patrz.nextLine();
  82.         String[] tab = nr.split("[ ]");
  83.        
  84.         for(int i = 0; i<tab.length; i++){
  85.             liczby.add(Integer.parseInt(tab[i]));
  86.         }
  87.        
  88.         Collections.sort(liczby);
  89.                
  90.         int siz = liczby.size();
  91.        
  92.         int od = siz-1;
  93.        
  94.         int dz = od/2;
  95.        
  96.         int med = liczby.indexOf(liczby.get(dz));
  97.  
  98.         System.out.println(liczby.get(med));
  99.     }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement