Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- /*
- Amon Guinan
- Program performs XOR logic.
- User inputs a binary number.
- Program compares number of 1s to 0s.
- If equal, false.
- Otherwise, true.
- */
- public class exercises_two {
- public static void main(String[] args) {
- System.out.println("Input a binary number.");
- Scanner input = new Scanner(System.in);
- String URL = input.nextLine();
- int n = 0;
- int y = 0;
- while(URL.indexOf("1") != -1){
- URL = URL.replaceFirst("1","y");
- y = y+1;
- }
- while(URL.indexOf("0") != -1){
- URL = URL.replaceFirst("0","n");
- n = n+1;
- }
- if(n==y)
- {
- System.out.print("0 , FALSE");
- }
- else
- {
- System.out.print("1 , TRUE");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement