Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Scanner;
- //import java.io.File;
- //import static sun.nio.ch.IOStatus.EOF;
- public class Main {
- public static void main(String[] args) throws IOException {
- Scanner in=new Scanner(System.in);
- InputStreamReader es=new InputStreamReader(System.in);
- BufferedReader br=new BufferedReader(es);
- for (int i = 0; i < i+1; i++) {
- String num=in.next();
- if(num.equals("0")){
- break;
- }else{
- Integer x=Integer.parseInt(num);
- String bin=Integer.toBinaryString(x);
- int sum=0;
- for (int j = 0; j <bin.length() ; j++) {
- char c=bin.charAt(j);
- String s=String.valueOf(c);
- int a=Integer.parseInt(s);
- sum=sum+a;
- }
- System.out.printf("The parity of %s is %d (mod 2).\n",bin,sum);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement