View Single Post
  #1 (permalink)  
Old 12-10-2007, 07:03 PM
hey hey is offline
Member
 
Join Date: Dec 2007
Posts: 21
hey is on a distinguished road
Read from console (Scanner Class)
Hi, today is the second day I am trying to get familiar with Java..I'm trying to implement reading from console.. When I use this Input class once, everything is ok, if I try to read to integers, I get exceptions and errors.. Please, help!
This is a main program
import java.util.Scanner;
import Input.Input;
class Min{
public static void main(String[] args){
int x=0,y=0,z=0, f=0, i=0;

x = Input.InputInt();
System.out.println(x);
y = Input.InputInt();
System.out.println(x);


}
}
and Input class itself
package Input;
import java.util.Scanner;
public class Input{
public static int InputInt(){
int x=0;
Scanner in = new Scanner(System.in);

//reads int from the console
//and stores into x

x=in.nextInt();
in.close();
return x;


}

}
Reply With Quote
Sponsored Links