里程(公尺) 費用
<1500 70元
>1500 每多500公尺+5元
*不足500公尺以500公尺計算
- import java.util.Scanner;
- public class C1
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- //輸入里程
- System.out.println("請輸入里程:");
- double a = input.nextDouble();
- //計算車資
- if(a<=1500)
- {
- System.out.println("車資為70元");
- }
- else if(a>1500)
- {
- int b = ( (int)a - 1001 ) / 500;
- int c = b * 5;
- System.out.println("車資為" + (70+c) + "元");
- }
- }
- }
沒有留言:
張貼留言