import java.io.*;
public class T1
{
public static void main(String[] args) throws IOException
{
short num;
InputStreamReader a=new InputStreamReader (System.in);
BufferedReader b=new BufferedReader (a);
System.out.pritln("请输入成绩: "+"分");
String c=b.readLine();
num=Float.parseFloat(c);
if (num>=90)
System.out.println("优秀");
if (num>=80)
System.out.println("一般");
if (num>=70)
System.out.println("良好");
if (num>=60)
System.out.println("合格");
else System.out.println("不合格");
}
}
上面一个小程序里,在CMD上运行后输入一个数据后判断成绩了,怎么样弄可以在输入第二个数据的时候不用再运行一次java t1来进行判断成绩?java
public class T1
{
public static void main(String[] args) throws IOException
{
short num;
InputStreamReader a=new InputStreamReader (System.in);
BufferedReader b=new BufferedReader (a);
System.out.pritln("请输入成绩: "+"分");
String c=b.readLine();
num=Float.parseFloat(c);
if (num>=90)
System.out.println("优秀");
if (num>=80)
System.out.println("一般");
if (num>=70)
System.out.println("良好");
if (num>=60)
System.out.println("合格");
else System.out.println("不合格");
}
}
上面一个小程序里,在CMD上运行后输入一个数据后判断成绩了,怎么样弄可以在输入第二个数据的时候不用再运行一次java t1来进行判断成绩?java
解决方案 »
- 请问这句话中的Integer.MIN_VALUE是什么意思?
- 怎么把从数据库读取的数据存入列表框???????
- 装了Eclipse JavaEE IDE之后还用再装JavaEE SDK吗?
- 请问在表中加入JComboBox的选择,为什么出现在一次点击上box中的内容为上一次里的内容
- 请问大侠 客户端接收soapMessage消息,除了selvet还有其他方法吗
- 有一个类找不到,不知该如何导入该类:java.lang.Thread.State
- 学习java中打包遇到的问题
- 有关线程的小问题
- 关于关闭窗口的程序
- 有人愿意帮初学的小师妹理解几个概念吗?
- 正则问题 m.groupCount() 和 m.find()
- FileOutputStream的刷新问题
import java.io.IOException;
import java.io.InputStreamReader;public class Test1 {
public static void main(String[] args) throws IOException {
float num;
InputStreamReader a = new InputStreamReader(System.in);
BufferedReader b = new BufferedReader(a);
System.out.println("请输入成绩: " + "分");
String c = b.readLine();
num = Float.parseFloat(c);
if (num >= 90)
System.out.println("优秀");
else if (num >= 80)
System.out.println("一般");
else if (num >= 70)
System.out.println("良好");
else if (num >= 60)
System.out.println("合格");
else
System.out.println("不合格");
}
}
} else if(){
}
当if()成立时,就不进入else if()了;当不成立时,进入else if()块。
import java.io.IOException;
import java.io.InputStreamReader;public class A {
private static void inner() throws Exception {
short num;
InputStreamReader a = new InputStreamReader(System.in);
BufferedReader b = new BufferedReader(a);
System.out.println("请输入成绩: " + "分");
String c = b.readLine();
if (c.equals("exit"))
System.exit(0);
else{
num = Short.parseShort(c);
if (num >= 90)
System.out.println("优秀");
if (num >= 80)
System.out.println("一般");
if (num >= 70)
System.out.println("良好");
if (num >= 60)
System.out.println("合格");
else
System.out.println("不合格");
}
inner();
} public static void main(String[] args) throws Exception {
inner();
}
}
while(!c.equals("end")){
...
}
return;
}
这个 InputStreamReader a=new InputStreamReader (System.in);回车了就没了!!!做个网页版的,不行吗?
Scanner scan = new Scanner(System.in);
int score = scan.nextInt();
if(score >=90){
System.out.println("Very good");
}else{
System.out.println("go ahead");
}
System.out.println("**********just demo ********");
50
不合格
请输入成绩: 分
60
合格
请输入成绩: 分
70
良好
合格
请输入成绩: 分
80
一般
良好
合格
请输入成绩: 分
exit
import java.io.IOException;
import java.io.InputStreamReader;
public class A {
private static void inner() throws Exception {
short num;
InputStreamReader a = new InputStreamReader(System.in);
BufferedReader b = new BufferedReader(a);
System.out.println("请输入成绩: " + "分");
String c = b.readLine();
// exit 跳出循环否则,不断读取输入;跳出执行system.exit(0),结束。
while(!c.equals("exit")) {
num = Short.parseShort(c);
if (num >= 90)
System.out.println("优秀");
else if (num >= 80)
System.out.println("一般");
else if (num >= 70)
System.out.println("良好");
else if (num >= 60)
System.out.println("合格");
else
System.out.println("不合格");
c = b.readLine();
}
System.exit(0);
}
public static void main(String[] args) throws Exception {
inner();
}
}这个程序没有很强的容错性,输入长int或者其他字母无法处理
public class T2
{
private static void inner() throws Exception
{
short num;
InputStreamReader a=new InputStreamReader(System.in);
BufferedReader b=new BufferedReader(a);
System.out.println("请输入成绩:"+"分");
String c=b.readLine();
while(!c.equals("exit"));
{
num=Short.parseShort(c);
if (num>=90)
System.out.println("优秀");
else if (num>=80)
System.out.println("一般");
else if (num>=70)
System.out.println("良好");
else if (num>=60)
System.out.println("合格");
else
System.out.println("不合格");
c=b.readLine();
}
System.exit(0);
}
public static void main(String[] args) throws Exception
{
inner();
}
}我对着来敲了一遍怎么什么都没的
//求行李问题,如果行李小于20kg不用钱,超过20kg就1.2元1kg
import java.io.*;
public class T2
{
public static void inner() throws Exception
{
double w,fee;
InputStreamReader a=new InputStreamReader(System.in);
BufferedReader b=new BufferedReader(a);
System.out.println("请输入行李重量");
w=Double.parseDouble(b.readLine());
while(!b.equals("exit"));
{
if(w>20)
fee=1.2*(w-20);
else
fee=0;
System.out.println(""+w+"Kg行李需要交纳: "+fee+"元");
}
System.exit(0);
}
public static void main(String[] args) throws Exception
{
inner();
}
}这个结果和上面的结果一样,都是在命令指示符上敲了,输入数据后就不能动了
死循环:
while(!b.equals("exit")); //执行空语句 ;
{ int a = 3;} //这句不会执行正确如下 :
while(!b.equals("exit"))
{ int a = 3;}
/**
*
* @param input
* 输入的成绩
*/
private static void showResult(String input) {
Float num;
num = Float.parseFloat(input);
if (num >= 90)
System.out.println("优秀");
else if (num >= 80)
System.out.println("一般");
else if (num >= 70)
System.out.println("良好");
else if (num >= 60)
System.out.println("合格");
else
System.out.println("不合格");
} public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请输入成绩: 分. [ Q = 退出 ]");
try {
String input = scanner.nextLine();
if (input.trim().length() > 0) {
if ("Q".equalsIgnoreCase(input)) {
break;
}
// 打印结果
showResult(input);
} } catch (Exception e) {
System.out.println("输入不正确 " + e.toString());
}
}
scanner.close();
}