View Single Post
  #11 (permalink)  
Old 12-12-2007, 12:11 AM
hey hey is offline
Member
 
Join Date: Dec 2007
Posts: 21
hey is on a distinguished road
Quote:
Originally Posted by staykovmarin View Post
Code:
import java.util.Scanner; class Min { public static void main(String[] args) { int x = 0, y = 0, z = 0, f = 0, i = 0; Input input = new Input(); x = input.InputInt(); System.out.println(x); y = input.InputInt(); System.out.println(y); input.close(); } } class Input { Scanner in; public int InputInt() { int x = 0; in = new Scanner(System.in); // reads int from the console // and stores into x x = in.nextInt(); return x; } public void close() { in.close(); } }
So after a little bit of reading, i found out that after you close a stream, it cant be reopened, even if you create a new one (although i swear that it worked fine when i did it :\ ) So here is another solution. Just close the stream after you are done getting the numbers.
But in this case, I cannot use that package Input as an independable.. i mean, I have to close the thread from the main program .. is that correct?
thnx
Reply With Quote