Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. package exercise_10;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Exercise_10 {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. int decimal, partition, remainder;
  10.  
  11. String binary = "";
  12.  
  13. Scanner input = new Scanner(System.in);
  14.  
  15. System.out.print("Въведи позитивно десетично число: ");
  16.  
  17. decimal = input.nextInt();
  18.  
  19. do {
  20.  
  21. partition = decimal / 2;
  22.  
  23. remainder = decimal % 2;
  24.  
  25. decimal = partition;
  26.  
  27. binary += remainder;
  28.  
  29. }
  30.  
  31. while (partition != 0);
  32.  
  33. System.out.println("Конвертирано в двоично число е: " + binary);
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement