Advertisement
s_m4rt

Untitled

Nov 18th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. package zpliku;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileReader;
  7. import java.io.IOException;
  8. import java.util.ArrayList;
  9. import java.util.Collections;
  10. import java.util.Scanner;
  11.  
  12. import javax.swing.JOptionPane;
  13.  
  14. public class Main {
  15.  
  16. public static void main(String[] args) {
  17.  
  18. parzyste();
  19. tylesamo();
  20.  
  21. }
  22. public static void parzyste() {
  23. int count=0;
  24. int c = 0;
  25. int t=0;
  26.  
  27. int j=0;
  28. try {
  29. Scanner input = new Scanner(System.in);
  30. File file = new File("plik.txt");
  31.  
  32. input = new Scanner(file);
  33.  
  34.  
  35. while (input.hasNextLine()) {
  36. String line = input.nextLine();
  37. //System.out.println(line);
  38. if(line.length()%2==0) count++;
  39.  
  40. }
  41. System.out.println(count);
  42.  
  43.  
  44. input.close();
  45.  
  46. } catch (Exception ex) {
  47. ex.printStackTrace();
  48. }
  49. }
  50. public static void tylesamo(){
  51.  
  52. int c = 0;
  53. int t=0;
  54. int j=0;
  55. try {
  56. Scanner input = new Scanner(System.in);
  57. File file = new File("plik.txt");
  58.  
  59. input = new Scanner(file);
  60.  
  61.  
  62. while (input.hasNextLine()) {
  63. String line = input.nextLine();
  64. //System.out.println(line);
  65. for(int i=0; i<line.length(); i++){
  66. if (line.charAt(i) == '0') c++;
  67. if (line.charAt(i) == '1') j++;
  68.  
  69. }
  70. if(c==j) t++;
  71. c=0; j=0;
  72.  
  73. }
  74.  
  75.  
  76. System.out.println(t);
  77.  
  78. input.close();
  79.  
  80. } catch (Exception ex) {
  81. ex.printStackTrace();
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement