import java.io.*;
public class u{
static int t;
public static int f(int n){
if(n<=1) t=1;
else {
f(n)=(f(n-1)+f(n-2));
t=f(n);
}
return t; }
public static void main(String args[] ){
int m,p;
u i=new u();
try{m=System.in.read();}catch(Exception e){System.out.println("Exception");}
p=u.f(m);System.out.println(p);
}}
參考答案:用System.in.read()读到的是输入字符的ASCII码,需要转换为char型的.
代码如下:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Char ch=(char)br.read();
这样才可以用.