Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package xor;
  7.  
  8. import java.util.ArrayList;
  9.  
  10. /**
  11. *
  12. * @author kamil
  13. */
  14. public class Xor {
  15.  
  16. /**
  17. * @param args the command line arguments
  18. */
  19. public static void main(String[] args) {
  20. String pom = new String("1100110011001110101011001111111000101101001000001010011101000110100110010011011110001000111111011101111001100011101000000000111011100101010100010111100110000111");
  21. String pod = new String("0011001001010110111100111011000011100000010111001011101100011000000101110001001011100110110111100111001100001101110100011111010000000001000010000001110100000101");
  22.  
  23. ArrayList<Boolean> boolpom = new ArrayList<>();
  24. ArrayList<Boolean> boolpom2 = new ArrayList<>();
  25.  
  26. uzuptabele(boolpom, pom);
  27. uzuptabele(boolpom2, pod);
  28.  
  29. double ilosc_znakow = pom.length();
  30. double roznica = 0;
  31.  
  32. for (int i = 0; i < boolpom.size(); i++) {
  33. if(boolpom.get(i)^boolpom2.get(i)==true){
  34. roznica++;
  35. }
  36. }
  37.  
  38. System.out.println("Roznica: "+(int)roznica+" znakow");
  39. System.out.println("Roznica %: "+(roznica/ilosc_znakow*100));
  40. }
  41.  
  42. public static void uzuptabele(ArrayList<Boolean> lista, String pom) {
  43. for (char c : pom.toCharArray()) {
  44. switch (c) {
  45. case '0':
  46. lista.add(Boolean.FALSE);
  47. break;
  48. case '1':
  49. lista.add(Boolean.TRUE);
  50. break;
  51. }
  52. }
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement