- 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.
35 Respuestas
+ 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));
}
}
+ 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));
}
}
+ 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));
}
}
+ 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
+ 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");
}
}
}
0
This is not an assignment XXX just i am asking how to do that code
0
I already did that code but it showing errors that's why i am asking correct code
0
Ok then post the code here so I can tell you what the problem is.
0
Okay i will post the code
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;
}
}
}
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));
}
}
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
0
public class Convertor
{
public static String toBinary(int num)
{
String binary="";
while(num>0)
{
binary=(num%2)+binary;
num/=2;
}
return binary;
}
}
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));
}
}
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));
}
}
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 :)
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));
}
}
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));
}
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));
}
}
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));
}
}