62,621
社区成员
发帖
与我相关
我的任务
分享
/**
*
* @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();
}
while(!b.equals("exit")); //执行空语句 ;
{ int a = 3;} //这句不会执行
正确如下 :
while(!b.equals("exit"))
{ int a = 3;}import java.io.BufferedReader;
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或者其他字母无法处理
package test2;
import java.io.BufferedReader;
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();
}
}System.out.println("请输入你的成绩:");
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 ********"); InputStreamReader a=new InputStreamReader (System.in);
回车了就没了!!!
做个网页版的,不行吗?