Advertisement
Ruhan_DIU

Problem B -VJ CONTEST

Oct 5th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Scanner;
  5.  
  6. //import java.io.File;
  7.  
  8. //import static sun.nio.ch.IOStatus.EOF;
  9.  
  10. public class Main {
  11.  
  12. public static void main(String[] args) throws IOException {
  13. Scanner in=new Scanner(System.in);
  14. InputStreamReader es=new InputStreamReader(System.in);
  15. BufferedReader br=new BufferedReader(es);
  16.  
  17.  
  18. for (int i = 0; i < i+1; i++) {
  19. String num=in.next();
  20. if(num.equals("0")){
  21. break;
  22. }else{
  23. Integer x=Integer.parseInt(num);
  24. String bin=Integer.toBinaryString(x);
  25. int sum=0;
  26. for (int j = 0; j <bin.length() ; j++) {
  27. char c=bin.charAt(j);
  28. String s=String.valueOf(c);
  29. int a=Integer.parseInt(s);
  30. sum=sum+a;
  31. }
  32. System.out.printf("The parity of %s is %d (mod 2).\n",bin,sum);
  33. }
  34.  
  35.  
  36. }
  37.  
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement