+ 1
Why does it ask for a return statement? I think I have one... Help please!
import java.util.Scanner; //your code goes here public class Converter{ 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)); } }
2 Antworten
+ 4
Paul Berger
It is giving error because it is not necessary to have num > 0 so return statement will not execute because it is written inside while loop.
So write return statement outside the loop.
+ 2
thanks alot!