+ 2

A program-problem related to JAVA..........

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) ); }

1st Feb 2022, 11:16 AM
Tripti Tiwari
Tripti Tiwari - avatar
3 Answers
+ 2
import java.util.Scanner; public class Converter { public static String toBinary(int num){ //here String binary=""; while(num>0) { binary =(num%2)+binary; num/=2; } return binary; }//here } public class Program { public static void main(String[]args){//here Scanner sc=new Scanner(System.in); int x=sc.nextInt(); System.out.print(Converter.toBinary(x) ); }//here }
1st Feb 2022, 12:37 PM
Bahha┣
Bahha┣ - avatar
+ 3
you are missing some { } toBinary(int num) { code here } main(String [] args) { }
1st Feb 2022, 11:58 AM
Bahha┣
Bahha┣ - avatar
+ 2
Please use relevant tags ☝ https://code.sololearn.com/W3uiji9X28C1/?ref=app
1st Feb 2022, 1:22 PM
Ipang