注册 登录
编程论坛 JAVA论坛

7-7 高速公路超速处罚 (5 分)

Lech小马 发布于 2018-11-12 18:11, 2316 次点击
按照规定,在高速公路上行使的机动车,达到或超出本车道限速的10%则处200元罚款;若达到或超出50%,就要吊销驾驶证。请编写程序根据车速和限速自动判别对该机动车的处理。

输入格式:
输入在一行中给出2个正整数,分别对应车速和限速,其间以空格分隔。

输出格式:
在一行中输出处理意见:若属于正常行驶,则输出“OK”;若应处罚款,则输出“Exceed x%. Ticket 200”;若应吊销驾驶证,则输出“Exceed x%. License Revoked”。其中x是超速的百分比,精确到整数。

输入样例1:
65 60
输出样例1:
OK
输入样例2:
110 100
输出样例2:
Exceed 10%. Ticket 200
输入样例3:
200 120
输出样例3:
Exceed 67%. License Revoked

import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);;
    int a=sc.nextInt();
    int b=sc.nextInt();
    if(a>=b*1.10 && a<b*1.50) {
        System.out.println("Exceed "+((a-b)*100/b)+"%. Ticket 200");
    }
    else if(a>=b*1.50){
        System.out.println("Exceed "+((a-b)*100/b)+"%. License Revoked");
    }
    else {
        System.out.println("OK");
    }
}
}
为啥我这个答案不是全对
1 回复
#2
林月儿2018-11-18 19:24
Scanner sc=new Scanner(System.in);;
    int a=sc.nextInt();
    int b=sc.nextInt();


Scanner sc = new Scanner(System.in);
String inputStr = sc.nextLine();
String[] arr = inputStr.split(" ");
if(arr.length!=2){
    return;
}
int a = Integer.parseInt(arr[0]);//NumberFormatException,TODO
int b = Integer.parseInt(arr[1]);
1