+ 1

Answer for java project binary converter.

Hello guys please answer

9th Jun 2021, 1:59 PM
Titanus Gojira
Titanus Gojira - avatar
11 odpowiedzi
+ 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
9th Jun 2021, 2:23 PM
Atul [Inactive]
+ 2
Thanks buddy
9th Jun 2021, 2:23 PM
Titanus Gojira
Titanus Gojira - avatar
+ 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
9th Jun 2021, 4:45 PM
Atul [Inactive]
0
Post your attempt first
9th Jun 2021, 2:05 PM
Atul [Inactive]
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)); } }
9th Jun 2021, 2:07 PM
Titanus Gojira
Titanus Gojira - avatar
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
10th Jun 2021, 3:19 AM
Atul [Inactive]
0
Martin Taylor Yes. If possible link the website as it will help all to know about java API
10th Jun 2021, 4:44 AM
Atul [Inactive]
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)); } }
19th Nov 2022, 4:33 AM
Pangui Tagne Cedrik Junior
Pangui Tagne Cedrik Junior - avatar