+ 1
Answer for java project binary converter.
Hello guys please answer
11 Answers
+ 10
import java.util.Scanner;
public class Converter{
public static String toBinary(int y){
String binary = "";
// int y;
while(y>0){
binary = (y%2)+binary;
y/= 2;
}
return binary ;
}
}
//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));
}
}
//Many silly mistakes are there I suggest you please go through the course ones again and use Google frequently too
+ 2
Thanks buddy
+ 2
Martin Taylor No in the course it is told to create a custom class . So did by Titanus Gojira Your answer can be an alternative I used give this answer to all who asks for shorter code of this problem
0
Post your attempt first
0
import java.util.Scanner;
public class Converter{
public static int toBinary(){
String binary = "";
int y;
while(y>0){
binary = (y%2)+binary;
y/= 2;
}
return y;
}
}
//your code goes here
public class Program {
public static void main(String[ ] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int x == int y;
System.out.print(Converter.toBinary(x));
}
}
0
Not like that Martin Taylor if you go through that excercise you will find that in the box it is provided with that part of code
0
Martin Taylor Yes. If possible link the website as it will help all to know about java API
0
// binary converter program in java
import java.util.Scanner;
//your code goes here
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();
Converter converter = new Converter();
System.out.print(Converter.toBinary(x));
}
}