Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- //your code goes here
- class Converter{
- public static String toBinary(int num){ //remember to include return type as String!
- String binary="";
- //Loop block is given
- while(num > 0) {
- binary = (num%2)+binary;
- num /= 2;
- }
- return binary; //to return the binary string in this method
- }
- }
- //This is given
- public class Program {
- public static void main(String[ ] args) {
- Scanner sc = new Scanner(System.in);
- int x = sc.nextInt();
- System.out.print(Converter.toBinary(x));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement