Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.util.*;
  5.  
  6. import javax.swing.JOptionPane;
  7.  
  8. public class Laborator3
  9. {
  10. public static void main(String[] args)
  11. {
  12. FileReader fr = null;
  13. BufferedReader bfr = null;
  14.  
  15. int max = 0;
  16.  
  17. try {
  18. fr = new FileReader("fisier.txt");
  19. bfr = new BufferedReader(fr);
  20.  
  21. for(;;)
  22. {
  23. String linie = bfr.readLine();
  24. if (linie == null) break; // s-a terminat fisierul
  25.  
  26. StringTokenizer tk = new StringTokenizer(linie);
  27.  
  28. for (int i = 0; i < tk.countTokens(); i++)
  29. {
  30. int nr = Integer.parseInt(tk.nextToken());
  31.  
  32. if (nr > max)
  33. {
  34. max = nr;
  35. }
  36. }
  37. }
  38.  
  39. fr.close();
  40. bfr.close();
  41.  
  42. if (max != 0)
  43. {
  44. System.out.println(max);
  45. }
  46. else
  47. {
  48. System.out.println("Nu exista");
  49. }
  50.  
  51. } catch(IOException e) {
  52. System.out.println(e);
  53. System.exit(1);
  54. }
  55.  
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement