+ 2
can anyone find error its showing cant find variable ki
package hdi; import java.util.Scanner; public class hdi { public static String pin(String x){ Scanner inp = new Scanner(System.in); System.out.println("Kindly input your number"); int ki = inp.nextInt(); Scanner inpu = new Scanner(System.in); System.out.println("kindly choose second number"); int kn = inpu.nextInt(); return ki; return kn; } public static void main(String[] args) {
1 Réponse
+ 3
Raghav...
notice on your method declaration that you are declaring that you are returning a string but variable ki and kn are of type int
to fix this you can do the following:
return new String(ki);
or even this
Interger [the class btw] ki = new Interger(inp.nextInt());
return ki.toString();
note there may be errors in this code since i did it from pure memory, look into the specifics of how to do this on google
Continuing...
you can only return one object. you cannot do
return variable;
return variable2;
they both must be in the same array in order to return multiple values.
so i recomend to do this
public static String[] pin() {
String[] arr = new String[2];
//scanner and printout code here
int ki = inp.nextInt();
arr[0] = new String(ki);
int kh = inp.nextInt();
arr[1] = new String(kh);
return arr;
}
you will need to add the variable for the scanner and i did do this from memory so there may be some errors
i hope this helps
happy coding