Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Problem: binary
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { NumbertoBinary obj = new NumbertoBinary(); Scanner input = new Scanner(System.in); int num = input.nextInt(); System.out.println("\nBinary representation of number: "); obj.convertBinary(num); } } class NumbertoBinary { public void convertBinary(int num) { int binary[] = new int[40]; int index = 0; while(num > 0) { binary[index++] = num%2; num = num/2; } for(int i = index-1;i >= 0;i--) { System.out.print(binary[i]); } } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Java
Problem_OnOff
Increment
Java Replace Method
Sort
pow x^n
Date and Time
Find Case Combinations of a String
Java # Dizi ile ek bulma
1.7
Please log in to post a comment.