I have a Java Programming question. I have the following code and at Scanner.nextLine(); it is telling
Question:
I have a Java Programming question. I have the following code and atScanner.nextLine();it is telling me that I \"Cannot make a static reference to the nonstatic method nextLine() from the type Scanner\" I can't figure out how to correct this.
importjava.io.PrintStream;
importjava.util.Scanner;
publicclassQuartsToGallonsWithExceptionHandling {
QuartsToGallonsWithExceptionHandling(){
}
publicstaticvoidmain(String args[]){
inti = 18;
booleanflag =false;
Scanner scanner =newScanner(System.in);
while(!flag)
try{
System.out.println(\"enter quarts needed >> \");;
i = scanner.nextInt();
flag =true;
}
catch(Exception exception){
Scanner.nextLine();
System.out.println(\"Invalid data entry\");
}
intj = i / 4;
intk = i / 4;
System.out.println((newStringBuilder()).append(\"A job that needs \")
.append(i).append(\" quarts requires \")
.append(j).append(\" gallons plus \")
.append(k).append(\" quarts.\").toString());
}