Advertisement
sudoaptinstallname

Untitled

Jan 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6. /*
  7. Amon Guinan
  8. Program performs XOR logic.
  9. User inputs a binary number.
  10. Program compares number of 1s to 0s.
  11. If equal, false.
  12. Otherwise, true.
  13. */
  14. public class exercises_two {
  15. public static void main(String[] args) {
  16.  
  17. System.out.println("Input a binary number.");
  18. Scanner input = new Scanner(System.in);
  19.  
  20. String URL = input.nextLine();
  21. int n = 0;
  22. int y = 0;
  23.  
  24. while(URL.indexOf("1") != -1){
  25. URL = URL.replaceFirst("1","y");
  26. y = y+1;
  27. }
  28.  
  29. while(URL.indexOf("0") != -1){
  30. URL = URL.replaceFirst("0","n");
  31. n = n+1;
  32. }
  33.  
  34. if(n==y)
  35. {
  36. System.out.print("0 , FALSE");
  37. }
  38. else
  39. {
  40. System.out.print("1 , TRUE");
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement