New course! Every coder should learn Generative AI!
Try a free lesson+ 1
I hava a error in my java code can anyone help please
Non static method cannot be referenced from a static context https://code.sololearn.com/c0A9MNJuQeIC/?ref=app For input: BritishAirways Economy 6
1 Answer
0
Use just one static Scanner instance instead of using different Scanner locally in various methods.
* Above main method addl
private static Scanner reader;
* Inside main method initialize the static Scanner
reader = new Scanner (System.in);
Use static Scanner <reader> for reading in the airways name, flight class and number of passengers. Discard local Scanner declaration from each method that uses Scanner to read input.
I tried this in Code Playground and it works 👌