Advertisement
gagoi

Integer to Binary

Jul 23rd, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. private static void test2() {
  2. char rep = 'N';
  3. do {
  4. System.out.println("Entrez le nombre : ");
  5. @SuppressWarnings("resource")
  6. Scanner sc = new Scanner(System.in);
  7. String nbBinary = (new StringBuffer(sc.nextLine()).reverse().toString());
  8. int value = 1;
  9. int answer = 0;
  10.  
  11. for (int i = 0; i < nbBinary.length(); i++) {
  12. if (nbBinary.charAt(i) == '1') {
  13. answer += value;
  14. }
  15. value += value;
  16. }
  17. System.out.println("R�ponse : " + answer);
  18.  
  19. System.out.println("Voulez-vous recommencez ? (O/N)");
  20. rep = sc.nextLine().charAt(0);
  21. } while (rep == 'O');
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement