+ 3
In this code the main method calls the Scanner first and then calls the x() method.How can I call the x() 1st and then Scanner?
import java.util.*; public class Main { public static void main(String[] args) { program x = new program(); x.x(); } } class program { Scanner x = new Scanner(System.in); void x(){ System.out.println("hi"); } String b = x.nextLine(); }
2 Respostas
+ 2
Use this:
void x(){
System.out.println("hi");
String b = x.nextLine();
}
But if i were you i should rename method name, the scanner reference variable to something else, if you do bigger projects and nameing it like that.. it will really confuse you
+ 2
This would be helpfull
void x(){
System.out.println("hi");
String b = x.nextLine();
}