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)); } }
5 odpowiedzi
+ 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));
}
}
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.
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));
}
}
0
Is it right?
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
}