Topic: 一个小程序

  Print this page

1.一个小程序 Copy to clipboard
Posted by: wslss007
Posted on: 2005-10-17 20:51

public class THE
{
public static void main(String args[]) {
String str1,str2;
BufferedReader buffer1;
buffer1=new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入紫外线指数");
str1=buffer1.readLine();
int x=Integer.parseInt(str1);
switch(x){
case 0:
case 1:
case 2:
case 3:
case 4:
str2="微量级";
break;
default:
str2="危险级";
}
System.out.println("级数"=+x+"为"+str2);

}
}

其中buffer1=new BufferedReader(new InputStreamReader(System.in));这个语句不明白什么意思,还有这个程序编译时有四个错误,请改正,谢谢。

2.Re:一个小程序 [Re: wslss007] Copy to clipboard
Posted by: bluecrystal
Posted on: 2005-10-17 21:08


import java.io.*; //你忘了import BufferedReader
public class THE {
public static void main(String args[]) throws Exception { //简单的捕获异常并抛出
String str1, str2;
BufferedReader buffer1;
//创建一个接受默认输入设备的接受缓冲,System.in这里就是控制台的键盘输入
buffer1 = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入紫外线指数:");
str1 = buffer1.readLine();
int x = Integer.parseInt(str1);
switch(x){
case 0:
case 1:
case 2:
case 3:
case 4:
str2="微量级";
break;
default:
str2="危险级";
}
System.out.println("级数"+x+"为"+str2);//你这里原来多了一个=号

}
}


多看看书,多根据调试给出的错误信息翻书或者资料
:)

测试输出:

D:\temp>java THE
请输入紫外线指数:
6
级数6为危险级


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923