美文网首页
2018-08-03作业

2018-08-03作业

作者: 黄昭鸿 | 来源:发表于2018-08-03 00:40 被阅读0次
import java.util.Scanner;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Console;

public class TaxiChristmasTree99MultiplicationTable {
    public static void main(String[] args) {
        ifTaxi();
        printChristmasTree();
        multiplicationTable();
    }

    @SuppressWarnings("resource")
    public static void ifTaxi() {
        // 起步价//路程//总费用//税费
        double startPrice = 6.0, distance = 0.0, totalCost = 0.0, taxation = 1.0;
        int startTime = 0;
        Scanner scanner = new Scanner(System.in);
        System.out.print("上车时间(整点):");// 2013-04-05 12:34:56
        if (scanner.hasNextInt()) {
            startTime = scanner.nextInt();
        } else {Console.log("输入时间点不是整数");System.exit(0);}

        // 路程
        System.out.print("路程:");
        if (scanner.hasNextDouble()) {
            distance = scanner.nextDouble();
        } else {Console.log("路程输入有误");System.exit(0);}

        // 起步价
        if (startTime <0 || startTime > 23) {
            Console.log("上车时间点输入有误");System.exit(0);
        } else if (startTime > 5 && startTime < 22) {           
            Console.log("白天" + startTime + "点,起步价6元");
        } else {
            //(startTime >= 0 && startTime < 6) || (startTime > 21 && startTime < 24)
            startPrice = 7.0;
            Console.log("晚上" + startTime + "点,起步价7元");
        }

        // 总费用
        if (distance < 0.0) {scanner.close();System.exit(0);}
        else if(distance<2.0) {totalCost = startPrice + taxation;}
        else{totalCost = startPrice + (distance - 2.0) * 1.5 + taxation;}
        
        System.out.println("总费用:¥" + totalCost + "(" + Convert.digitToChinese(totalCost) + ")");
        // scanner.close();//程序块单独运行时
    }

    // 九九乘法表
    public static void multiplicationTable() {
        Console.log("九九乘法表正序:");
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j + "x" + i + "=" + i * j + "\t");
            }
            Console.log();
        }
        /*
         * Console.log("九九乘法表倒序:"); for (int i = 9; i >= 1; i--) { for (int j =
         * 1; j <= i; j++) { System.out.print(j + "x" + i + "=" + i * j + "\t");
         * } Console.log(); }
         */
    }

    // 打印圣诞树,*=2x行号-1;" "=n行数-行号
    public static void printChristmasTree() {
        Console.log("输入圣诞树高度(<65):");
        Scanner scanner = new Scanner(System.in);
        byte n = 15, i = 1;// 行数,行号
        if (scanner.hasNextByte()) {
            n = scanner.nextByte();
            for (byte j = i; j <= n; j++) {
                for (byte k = 0; k < (n - j); k++) {System.out.print(" ");}
                for (byte j2 = 0; j2 < (2 * j - 1); j2++) {System.out.print("*");}
                Console.log();
            }
        } else {
            Console.log("输入有误");
        }
        scanner.close();
    }
}

相关文章

  • 2018-08-08

    2018-08-03 c6_李晓红Dorothy 2018-08-03 15:38 · 字数 269 · 阅读 0...

  • 2018-08-03作业

  • android 代码调用 home 触发

    2018-08-03记录下代码调用home触发 Intent backHome = new Intent(Inte...

  • github 个人博客搭建笔记

    title: github 个人博客搭建笔记date: 2018-08-03 17:32:13tags: 前端 个...

  • 2018-08-03

    游戏中的幸福 MaleGod_贺 2018-08-03 21:07 · 字数 1055 · 阅读 0 · 日记本 ...

  • cmder工具

    Date='2018-08-03' author="jolting" 今天偶然看一个学习视频,看到人家的命令行界面...

  • [转]Qt在pro文件中添加路径的方法

    原创yang_half 最后发布于2018-08-03 19:43:20 阅读数 3970 收藏 添加路径: IN...

  • UEditor .net版本 getshell

    发布时间:2018-08-03 公开时间:2018-08-21 漏洞类型:逻辑漏洞 危害等级:高 漏洞编号:xia...

  • 2018-08-03

    “知识—见识—人格”,读书的三重境界 见字_如唔 已关注 2018-08-03 21:26 · 字数 6554 ·...

  • 2018-08-03

    西瓜成长记(四) 风中的一棵树 2018-08-03 00:00 · 字数 309 · 阅读 0 · 日记本 ...

网友评论

      本文标题:2018-08-03作业

      本文链接:https://www.haomeiwen.com/subject/rgmevftx.html