i'm new to java so please do explain in full were i'm going wrong thank you.
import java.util.Scanner;
class apples {
public static void main (String args[]){
Scanner Nommy = new Scanner (System.in);
System.out.println (Nommy.nextLine());
}
}
i'm new to java so please do explain in full were i'm going wrong thank you.
import java.util.Scanner;
class apples {
public static void main (String args[]){
Scanner Nommy = new Scanner (System.in);
System.out.println (Nommy.nextLine());
}
}
To understand what's wrong, you should learn more about streams
stuff.
Briefly, if you open
stream, then, you should close
it, or a memory leak appears.
See http://www.tutorialspoint.com/java/java_files_io.htm for details.
Good luck!
You should close
the scanner after using it. Otherwise, you'll get the warning from the compiler.
The simplest way is to add Nommy.close()
after the last statement.
You should, however, call it in a finally
block or using the try
statement: see https://stackoverflow.com/a/15613676/1547337