0

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());
  }
}
hagrawal7777
  • 14,103
  • 5
  • 40
  • 70
Nehman
  • 43
  • 1

2 Answers2

1

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!

ar4ers
  • 740
  • 5
  • 19
0

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

Community
  • 1
  • 1
dejvuth
  • 6,986
  • 3
  • 33
  • 36