当前位置: 技术问答>java相关
一个很简单的Java程序。我是新手,请指点
来源: 互联网 发布时间:2015-08-07
本文导语: import java.io.*; public class snow{ public static void main(String args[]){ int c,b; System.out.print("Please enter v of c:"); try{ c=(int)System.in.read(); }catch(IOException e){}; b=c+18; System.out.print(...
import java.io.*;
public class snow{
public static void main(String args[]){
int c,b;
System.out.print("Please enter v of c:");
try{
c=(int)System.in.read();
}catch(IOException e){};
b=c+18;
System.out.print("b="+b);
}
}
我错在哪里我不知道,javac老是说c may not have been initialize.
请指点一下好吗!谢谢!
public class snow{
public static void main(String args[]){
int c,b;
System.out.print("Please enter v of c:");
try{
c=(int)System.in.read();
}catch(IOException e){};
b=c+18;
System.out.print("b="+b);
}
}
我错在哪里我不知道,javac老是说c may not have been initialize.
请指点一下好吗!谢谢!
|
import java.io.*;
public class snow {
public static void main(String args[]) throws IOException {
int d,b;
String c;
BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter v of c:");
c=keyin.readLine(); \这里可输入多个数(其实是字符)
d=Integer.parseInt(c);
b=d+18;
System.out.println("b="+b);
}
}
这样应该就没有问题了
public class snow {
public static void main(String args[]) throws IOException {
int d,b;
String c;
BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter v of c:");
c=keyin.readLine(); \这里可输入多个数(其实是字符)
d=Integer.parseInt(c);
b=d+18;
System.out.println("b="+b);
}
}
这样应该就没有问题了