Advertisement
s_m4rt

Untitled

Nov 18th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. package zpliku;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.BufferedWriter;
  5. import java.io.File;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileOutputStream;
  8. import java.io.FileReader;
  9. import java.io.FileWriter;
  10. import java.io.IOException;
  11. import java.io.PrintStream;
  12. import java.util.ArrayList;
  13. import java.util.Collections;
  14. import java.util.Scanner;
  15.  
  16. import javax.swing.JOptionPane;
  17.  
  18. public class Main {
  19.  
  20. public static void main(String[] args) throws FileNotFoundException {
  21. zapisz();
  22. parzyste();
  23. tylesamo();
  24. czesctrzecia();
  25. cztery();
  26.  
  27. }
  28. public static void parzyste() {
  29. int count=0;
  30. int c = 0;
  31. int t=0;
  32.  
  33. int j=0;
  34. try {
  35. Scanner input = new Scanner(System.in);
  36. File file = new File("plik.txt");
  37.  
  38. input = new Scanner(file);
  39.  
  40.  
  41. while (input.hasNextLine()) {
  42. String line = input.nextLine();
  43. //System.out.println(line);
  44. if(line.length()%2==0) count++;
  45.  
  46. }
  47.  
  48. System.out.println("Napisow o parzystej dlugosci jest: " + count);
  49.  
  50.  
  51. input.close();
  52.  
  53. } catch (Exception ex) {
  54. ex.printStackTrace();
  55. }
  56. }
  57. public static void tylesamo(){
  58.  
  59. int c = 0;
  60. int t=0;
  61. int j=0;
  62. try {
  63. Scanner input = new Scanner(System.in);
  64. File file = new File("plik.txt");
  65.  
  66. input = new Scanner(file);
  67.  
  68.  
  69. while (input.hasNextLine()) {
  70. String line = input.nextLine();
  71. //System.out.println(line);
  72. for(int i=0; i<line.length(); i++){
  73. if (line.charAt(i) == '0') c++;
  74. if (line.charAt(i) == '1') j++;
  75.  
  76. }
  77. if(c==j) t++;
  78. c=0; j=0;
  79.  
  80. }
  81.  
  82.  
  83. System.out.println("Tyle samo zer i jedynek jest: "+ t);
  84.  
  85. input.close();
  86.  
  87. } catch (Exception ex) {
  88. ex.printStackTrace();
  89. }
  90. }
  91. public static void czesctrzecia(){
  92. int jedynki=0;
  93. int zera=0;
  94. int onlyzero=0;
  95. int onlyone=0;
  96. try {
  97. Scanner input = new Scanner(System.in);
  98. File file = new File("plik.txt");
  99.  
  100. input = new Scanner(file);
  101.  
  102.  
  103. while (input.hasNextLine()) {
  104. String line = input.nextLine();
  105. for (int i=0; i<line.length(); i++){
  106. if(line.charAt(i) == '0') zera++;
  107. if(line.charAt(i) == '1') jedynki++;
  108. }
  109. if(zera == line.length()) onlyzero++;
  110. if(jedynki == line.length()) onlyone++;
  111. zera=0; jedynki=0;
  112. }
  113.  
  114. System.out.println("Zer jest: " + onlyzero);
  115. System.out.println("Jedynek jest: "+onlyone);
  116.  
  117. input.close();
  118.  
  119. } catch (Exception ex) {
  120. ex.printStackTrace();
  121. }
  122. }
  123. public static void cztery(){
  124. int[] tablica=new int[15];
  125. try {
  126. Scanner input = new Scanner(System.in);
  127. File file = new File("plik.txt");
  128.  
  129. input = new Scanner(file);
  130.  
  131.  
  132. while (input.hasNextLine()) {
  133. String line = input.nextLine();
  134. if(line.length()==2) tablica[0]++;
  135. if(line.length()==3) tablica[1]++;
  136. if(line.length()==4) tablica[2]++;
  137. if(line.length()==5) tablica[3]++;
  138. if(line.length()==6) tablica[4]++;
  139. if(line.length()==7) tablica[5]++;
  140. if(line.length()==8) tablica[6]++;
  141. if(line.length()==9) tablica[7]++;
  142. if(line.length()==10) tablica[8]++;
  143. if(line.length()==11) tablica[9]++;
  144. if(line.length()==12) tablica[10]++;
  145. if(line.length()==13) tablica[11]++;
  146. if(line.length()==14) tablica[12]++;
  147. if(line.length()==15) tablica[13]++;
  148. if(line.length()==16) tablica[14]++;
  149.  
  150.  
  151. }
  152. int j=2;
  153. for (int i=0; i<tablica.length; i++){
  154. System.out.println(j+" znaki: " + tablica[i]);
  155. j++; }
  156.  
  157. input.close();
  158.  
  159. } catch (Exception ex) {
  160. ex.printStackTrace();
  161. }
  162. }
  163. public static void zapisz() throws FileNotFoundException {
  164.  
  165. PrintStream console = System.out;
  166.  
  167. File file = new File("rozw.txt");
  168. FileOutputStream fos = new FileOutputStream(file);
  169. PrintStream ps = new PrintStream(fos);
  170. System.setOut(ps);
  171.  
  172. }
  173.  
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement