0

Anybody tells how to solve type error?

import java.util.Scanner; public class converter{ toBinary(){ int x = 0; return 0; } toBinary(int x){ String binary =""; while(i>0){ binary = (i%2)+ binary; i /=2; } } } //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)); } }

14th Sep 2021, 5:55 AM
Amala Yakin
5 Respuestas
+ 1
Amala Yakin try this code i edit it import java.util.Scanner; public class converter{ public static void toBinary(){ int x = 0; } public static String toBinary (int x){ String binary =""; while(x>0){ binary = x%2 + binary; x /=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)); } }
14th Sep 2021, 6:30 AM
Maninder $ingh
Maninder $ingh - avatar
0
Your code has lot of errors. Return type is not defined for function. Where is i variable come from in tobinary() function? Solve it proper.
14th Sep 2021, 6:14 AM
Maninder $ingh
Maninder $ingh - avatar
0
import java.util.Scanner; public class converter{ public static int toBinary(){ int x = 0; return x; } public static int toBinary (int x){ String binary =""; while(x>0){ binary = x%2 + binary; x /=2; } } } //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)); } }
14th Sep 2021, 6:21 AM
Amala Yakin
0
Is it right?
14th Sep 2021, 6:21 AM
Amala Yakin
0
eg suppose the method returns a String, then String method() { //return type before method name String s = "abc"; return s; //return value of type declared above }
14th Sep 2021, 6:25 AM
zemiak