Created
November 1, 2017 13:15
-
-
Save DiegoTc/5af14524d0a86e07107ec3d76091960a to your computer and use it in GitHub Desktop.
Ejercicio de Victor Sandoval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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