Skip to content

Instantly share code, notes, and snippets.

@DiegoTc
Created November 1, 2017 13:15
Show Gist options
  • Save DiegoTc/5af14524d0a86e07107ec3d76091960a to your computer and use it in GitHub Desktop.
Save DiegoTc/5af14524d0a86e07107ec3d76091960a to your computer and use it in GitHub Desktop.
Ejercicio de Victor Sandoval
public class Ceutec {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int x = Integer.parseInt(args [0]);
int resp = x;
int cont = 0;
while(resp/2>0){
resp = resp/2;
cont = cont + 1;
}
int n = cont+1;
int[] a = new int[n];
int[] b = new int[n];
for (int j = 0; j < n; j++){
if (x%2!=0) {
a[j] = 1;
}else{
a[j] = 0;
}
resp = x / 2;
x = resp;
}
for(int i=0;i<(n/2);i++){
int temp = a[i];
a[i] = a[n - 1 - i];
a[n - 1 - i] = temp;
}
for(int p=0;p<n;p++){
System.out.print(a[p]);
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment