Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. package kolos2_zad1;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.util.ArrayList;
  6. import java.util.Arrays;
  7.  
  8. class Pomocnicza {
  9.  
  10. int ileliczb, suma;
  11.  
  12. Pomocnicza(int ile, int s) {
  13. ileliczb = ile;
  14. suma = s;
  15. }
  16.  
  17. public String toString() {
  18. return "liczb: " + ileliczb + " suma: " + suma + "\n";
  19. }
  20. }
  21. class Tekst{
  22. String[] tablicaStringow;
  23. Tekst(String[] a){
  24. tablicaStringow = a;
  25. }
  26. public String toString(){
  27. return ""+Arrays.toString(tablicaStringow);
  28. }
  29. }
  30. class Liczby {
  31.  
  32. ArrayList<Pomocnicza> lista = new ArrayList<>();
  33. ArrayList<Tekst> string = new ArrayList<>();
  34. int pom,i;
  35.  
  36. void wczytajPlik(String nazwa) {
  37. try {
  38. BufferedReader reader = new BufferedReader(new FileReader(nazwa));
  39. String[] tab;
  40. String line;
  41. while ((line = reader.readLine()) != null) {
  42.  
  43. tab = line.split(" ");
  44. string.add(new Tekst(tab));
  45. for (i = 0; i < tab.length; i++) {
  46. pom += Integer.parseInt(tab[i]);
  47. }
  48. lista.add(new Pomocnicza(tab.length, pom));
  49. pom = 0;
  50. }
  51.  
  52. } catch (Exception e) {
  53. System.out.println("Cos nie tak: " + e);
  54. }
  55.  
  56. }
  57. void sortuj(){
  58. int pom2;
  59. for(i=0;i<lista.size();i++){
  60. if(lista.get(i).ileliczb<lista.get(i+1).ileliczb){
  61. pom2=lista.get(i).ileliczb;
  62. // lista.set(i).ileliczb=lista.get(i+1).ileliczb
  63. }
  64. }
  65. }
  66. }
  67.  
  68. public class Kolos2_zad1 {
  69.  
  70. public static void main(String[] args) {
  71. Liczby X = new Liczby();
  72. X.wczytajPlik("kolo2_dane5.txt");
  73. System.out.println(X.lista);
  74. System.out.println(X.string);
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement