Advertisement
Jurado001

TP2E6 - Principal

Sep 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Stack;
  3.  
  4. public class Principal {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner S = new Scanner(System.in);
  8.         char resp;
  9.         do {
  10.             System.out.print("Ingrese un numero entero(BASE 10): ");
  11.             int D = S.nextInt();
  12.             Convertir(D);
  13.             System.out.println();
  14.             System.out.println("Desea convertir otro numero? s/n");
  15.             resp = S.next().charAt(0);
  16.             System.out.println();
  17.         }while(resp == 's' || resp == 'S');
  18.     System.out.println("Fin del Programa...");
  19.     }
  20.    
  21.     public static void Convertir(int D) {
  22.         Stack<Integer> p1 = new Stack<Integer>();
  23.         int C,R;
  24.         do {
  25.             C = D / 2;
  26.             R = D % 2;
  27.             p1.push(R);
  28.             D = C;
  29.         }while(D >= 2);
  30.         p1.push(D);
  31.        
  32.         Acomodar(p1);
  33.     }
  34.    
  35.     public static void Acomodar(Stack<Integer>p1) {
  36.         Integer[]datos=new Integer[p1.size()];
  37.         p1.toArray(datos);
  38.         System.out.print("El numero en base binaria es: ");
  39.         for(int i=datos.length-1; i>=0; i--) {
  40.             System.out.print(datos[i]);
  41.         }
  42.         System.out.println();
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement