Re: How can a user type in an int value?

From: gajo (gajo_at_eunet.yu)
Date: 10/19/03


Date: Sun, 19 Oct 2003 14:30:33 +0200


"Gordon Beaton" <not@for.email> wrote in message
news:3f926a75$1@news.wineasy.se...
> Then do Integer.parseInt(line) to get the value from the line.

Do I need to import the parseInt method from somewhere? Cause I get the
following error:

Faktoriel.java:16: cannot resolve symbol
symbol : method parseInt (int)
location: class java.lang.Integer
  int i = Integer.parseInt(j);
                 ^

Here's the whole code --->

import java.io.*;

class Faktoriel {
 public static int F(int n) {
  if (n<=1) return 1;
  else return n*F(n-1);
 }

 public static void main (String [] arg) throws Exception {
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Faktoriel program");
  System.out.println(" ");
  System.out.print("Type in a number: ");
  int j = in.read();
  int i = Integer.parseInt(j);
  System.out.println(" ");
  System.out.print(i+"! = ");
  int k = F(i);
  System.out.println(k);
 }

}



Relevant Pages