import java.io.*; class ReadNumber1 { // Demonstrating writing your own string->integer converter // (recursive version) public static void main(String[] args) throws IOException { String num; int n; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please type an integer : "); num=in.readLine(); n=stringToInt(num); System.out.println("The number you typed is: "+n); } public static int stringToInt(String str) { char last; String rest; if(str.length()==0) return 0; last=str.charAt(str.length()-1); rest=str.substring(0,str.length()-1); return stringToInt(rest)*10+convert(last); } private static int convert(char ch) { switch(ch) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; } return 0; } }