Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package javaapplication12;
  7.  
  8. import java.util.Scanner;
  9. import java.util.Stack;
  10.  
  11. /**
  12.  
  13. {
  14. * @author Lenovo1
  15. */
  16. public class JavaApplication12 {
  17. /**
  18. * @param args the command line arguments
  19. */
  20. public static void main(String[] args) {
  21. // TODO code application logic here
  22.  
  23. Scanner in = new Scanner(System.in);
  24.  
  25. Stack<Integer> stack = new Stack<Integer>();
  26.  
  27. System.out.println("Adj be egy binaris szamot! ");
  28. int num = in.nextInt();
  29.  
  30. if (num < 256 && num > 0)
  31. {
  32. while (num != 0)
  33. {
  34. int d = num % 2;
  35. stack.push(d);
  36. num /= 2;
  37. }
  38.  
  39. System.out.print("\nBinarisan ez:");
  40. while (!(stack.isEmpty() ))
  41. {
  42. System.out.print(stack.pop());
  43. }
  44. System.out.println();
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement