- 1

The binary numeric system uses only two digits: 0 and 1. Computers operate in binary, meaning they store data and perform calcul

The binary numeric system uses only two digits: 0 and 1. Computers operate in binary, meaning they store data and perform calculations using only zeros and ones. You need to make a program to convert integer numbers to their binary representation. Create a Converter class with a static toBinary() method, which returns the binary version of its argument. The code in main takes a number as input and calls the corresponding static method. Make sure the code works as expected.

2nd Jan 2021, 12:21 PM
Shaik Masthan
Shaik Masthan - avatar
35 Antworten
+ 58
import java.util.Scanner; public class Converter { public static String toBinary(int num) { String binary=""; while(num > 0) { binary = (num%2)+binary; num /= 2; } return binary; } } 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)); } }
13th Feb 2021, 11:03 AM
Rajkumar Shil
Rajkumar Shil - avatar
+ 7
import java.util.Scanner; //your code goes here public class Converter { public static String toBinary(int num) { String binary=""; while(num > 0) { binary = (num%2)+binary; num /= 2; } return binary; } } 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)); } }
2nd Mar 2021, 3:19 AM
Sasanka Vikum Vitharana
Sasanka Vikum Vitharana - avatar
+ 3
import java.util.Scanner; //your code goes here public class Converter{ public static String toBinary(int num){ String binary=""; while(num > 0) { binary = (num%2)+binary; num /= 2; } return binary; } } //Please Subscribe to My Youtube Channel //Channel Name: Fazal Tuts4U 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)); } }
4th Sep 2021, 7:48 AM
Fazal Haroon
Fazal Haroon - avatar
+ 1
After following course one by one step by step patiently, finally I can find my way to solve this problem You have to understand static kw, what is it for etc pls check my code here https://code.sololearn.com/ca38A4a1943A
30th Mar 2021, 1:17 AM
Lucky Junihardi
Lucky Junihardi - avatar
+ 1
/////////////////////////class convertir//////// public class Convert { public static String toBinary(int num) { String binary=""; while(num > 0) { binary = (num%2)+binary; num /= 2; } return binary; } } ///////////////////class test///////////////////// import java.util.*; public class Test { public static void main(String[] args) { int x=1; while(x>0) { System.out.println("entre votre nombre pour convertir de binaire"); Scanner sc = new Scanner(System.in); x = sc.nextInt(); System.out.print(Convert.toBinary(x)+"\n"); } } }
15th Dec 2021, 4:54 PM
abdellali majdoubi
abdellali majdoubi - avatar
0
This is not an assignment XXX just i am asking how to do that code
2nd Jan 2021, 12:39 PM
Shaik Masthan
Shaik Masthan - avatar
0
I already did that code but it showing errors that's why i am asking correct code
2nd Jan 2021, 12:44 PM
Shaik Masthan
Shaik Masthan - avatar
0
Ok then post the code here so I can tell you what the problem is.
2nd Jan 2021, 12:45 PM
XXX
XXX - avatar
0
Okay i will post the code
2nd Jan 2021, 12:46 PM
Shaik Masthan
Shaik Masthan - avatar
0
import java.util.Scanner; //your code goes here 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)); String binary=""; while(num > 0){ binary = (num%2)+binary; num /=2; } } }
2nd Jan 2021, 12:47 PM
Shaik Masthan
Shaik Masthan - avatar
0
import java.util.Scanner; //your code goes here public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); System.out.println(Integer.toBinaryString(x)); } }
7th Feb 2021, 4:02 PM
dammika rajapaksha
dammika rajapaksha - avatar
0
import java.util.Scanner; //your code goes here public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); System.out.println(Integer.toBinaryString(x)); } } public class Convertor { public static String toBinary(int num) { String binary=""; while(num>0) { binary=(num%2)+binary; num/=2; } return binary; } } You might see this for aid and follow me on insta:www.instagram.com/vipulruless and Youtube: https://www.youtube.com/channel/UCYqM-AlwKVrfotOYmoGgdPQ to connect and discussing any problem
8th Mar 2021, 8:33 AM
Vipul Harihar
Vipul Harihar - avatar
0
public class Convertor { public static String toBinary(int num) { String binary=""; while(num>0) { binary=(num%2)+binary; num/=2; } return binary; } }
14th Jun 2021, 2:39 PM
Harold Williams
Harold Williams - avatar
0
import java.util.Scanner; public class Converter{ public static String toBinary(int num){ String binary=""; while(num > 0) { binary = (num%2)+binary; num /= 2; } return binary; } } 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)); } }
22nd Jul 2021, 12:46 PM
SAGAR PRAMANIK
SAGAR PRAMANIK - avatar
0
import java.util.Scanner; //your code goes here public class Converter{ public static String toBinary(int num){ String binary=""; while(num>0){ binary=(num%2)+binary; num/=2; } return binary; } } 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)); } }
18th Sep 2021, 3:54 PM
Chandramouli
Chandramouli - avatar
0
import java.util.Scanner; public class Converter { public static String toBinary(int num) { String binary=""; while(num > 0) { binary = (num%2)+binary; num /= 2; } return binary; } } 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)); } } Worked :)
23rd Oct 2021, 6:10 PM
Alireza Nasrollahzadeh
Alireza Nasrollahzadeh - avatar
0
import java.util.Scanner; //your code goes here public class Converter { public static String toBinary(int num) { String binary=""; while(num > 0) { binary = (num%2)+binary; num /= 2; } return binary; } } 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)); } }
15th Nov 2021, 5:39 AM
Nabila Muftia Ma'ruf Kartono
Nabila Muftia Ma'ruf Kartono - avatar
0
Absoly it is not so hard. You have to create a class named Converter, then a method named toBinary and then the return. Here is my solution: import java.util.Scanner; //your code goes here public class Converter{ public static String toBinary(int num){ String binary=""; while(num > 0) { binary = (num%2)+binary; num /= 2; } return binary; } } 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)); }
23rd Nov 2021, 2:23 PM
Diego Fernández M.
Diego Fernández M. - avatar
0
import java.util.Scanner; class Converter{ static String binary=""; Converter(String b){ this.binary=b; } static int toBinary(int num){ while(num > 0) { binary = (num%2) + binary; num /= 2; } return num; } } 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)); } }
6th Dec 2021, 1:53 PM
Ibrahim Ahmad
Ibrahim Ahmad - avatar
0
import java.util.Scanner; public class Converter { public static String toBinary(int num) { String binary=""; while(num > 0) { binary = (num%2)+binary; num /= 2; } return binary; } } 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)); } }
17th Dec 2021, 9:29 AM
Mirmahmud Ilyosov
Mirmahmud Ilyosov - avatar