Java日常练习5 Java从入门到放弃篇16

因为,这几天在刷题 。觉得Java也有段时间没发文了 。今天有时间,接着跟大家分享一波Java编程 。
首先,我们先在src文件夹中新建一个名为的包,接着再新建名为的Java文件 。最后,再将下面的代码放进文件中 。
代码如下图:
package second;/*** Author:Mr.Pan_学狂* Finish_time:2021/4/11/23:13* Java Practice*/import java.util.*;class Example12{public static void main(String[] args) {System.out.println("Java使我快乐!!");System.out.println();test();test2();test3();test4();test5();test6();test7();test8();test9();test10();test11();test12();test13();test14();test15();test16();test17();test18();test19();}public static void test() {System.out.println("第一道练习题");//计算圆柱体的体积//面积=半径*半径*π//体积=面积*高Scanner input = new Scanner(System.in);//创建输入对象System.out.print("请输入圆柱体的半径和高:");//当行输入double r = input.nextDouble();//输入圆柱体的半径double Height = input.nextDouble();//输入圆柱体的高double S = Math.pow(r,2) * Math.PI;//圆面积的计算公式,S = r * r * PIdouble Volume = S * Height;//体积计算公式,Volume = S * HeightSystem.out.printf("圆柱体的面积是%2.4f\n",S);//格式化输出,保留4位小数System.out.printf("圆柱体的体积是%4.1f\n",Volume);//格式化输出,保留1位小数System.out.println();}public static void test2() {System.out.println("第二道练习题");Scanner input = new Scanner(System.in);//创建输入对象System.out.print("请输入英尺数:");//当行输入double feet = input.nextDouble();//获取输入的英尺数,double类型,双精度浮点数 。double Metre = feet * 0.305;//米与英尺之间的换算公式System.out.printf(feet+"英尺是%1.2f米\n",Metre);/*米的整数长度设为1(可自增),小数设为2位 。保留两位小数*/System.out.println();}public static void test3() {System.out.println("第三道练习题");Scanner input = new Scanner(System.in);//创建一个输入对象System.out.print("请输入磅数:");double Pounds = input.nextDouble();//获取输入的磅数double KG = Pounds * 0.454;System.out.printf(Pounds+"磅是%1.3f千克\n",KG);//格式化输出,保留三位小数System.out.println();}public static void test4() {System.out.println("第四道练习题");Scanner input = new Scanner(System.in);System.out.print("请输入费用与酬金率:");double pay = input.nextDouble();//费用double CJLV = input.nextDouble();//酬金率CJLV = (CJLV / 100);//酬金率换算double money = pay * CJLV;//酬金double All_pay = pay + money;//费用加上酬金,总费用System.out.printf("酬金是%1.2f,总费用为%1.2f\n",money,All_pay);//格式化输出,保留两位小数 。System.out.println();}public static void test5() {System.out.println();System.out.println("第五道练习题");Scanner input = new Scanner(System.in);//创建输入对象System.out.print("请输入一个整数(三位数):");int Integer = input.nextInt();//获取输入的整数int first_num = Integer % 10;//计算第一个数字int second_num = (Integer / 10) % 10;int third_num = Integer / 100;int sum = first_num + second_num + third_num;System.out.println("各位数字的求和结果是"+sum);System.out.println();}public static void test6() {System.out.println("第六道练习题");Scanner input = new Scanner(System.in);System.out.print("请输入分钟数:");int minutes = input.nextInt();int hours = minutes / 60;//小时与分钟数的转换int days = hours / 24;//天数与小时数的转换int years = days / 365;//年数与天数的转换int day = days % 365;//余下多少天System.out.println(minutes+"分钟是 "+years+"年 和 "+day+"天");System.out.println();}public static void test7() {System.out.println("第七道练习题");Scanner input = new Scanner(System.in);//创建输入对象System.out.print("请输入整数,[0,128]:");//当行输入int Ord_num = input.nextInt();//接收字符的整数值char change_char = (char)(Ord_num);//转换成字符System.out.println("整数"+Ord_num+"转换成字符"+change_char);System.out.println();}public static void test8() {System.out.println("第八道练习题");//财务应用程序,工资单 。Scanner input = new Scanner(System.in);//创建输入对象System.out.print("请输入员工的名字:");//当行输入String name = input.next();//获取输入的字符串,名字System.out.print("请输入工作时间:");int time = input.nextInt();//获取工作时间System.out.print("每小时赚多少美元?");double time_money = input.nextDouble();//每小时赚的钱System.out.print("联邦所得税率:");//联邦所得税率double LBSLV = input.nextDouble();double LBSLV2 = LBSLV * 100;System.out.print("州所得税率:");//州所得税率double ZSLV = input.nextDouble();double ZSLV2 = ZSLV * 100;double gross_pay = time_money * time;//总工资double Federal_Withholding = gross_pay * LBSLV;//联邦税扣除的钱double State_Withholding = gross_pay * ZSLV;//州扣除的钱double Total_Deduction = Federal_Withholding + State_Withholding;//总计扣除的钱double Last_money = gross_pay - Total_Deduction;//剩余的钱System.out.println("员工名字:"+name);System.out.println("工作时间:"+time);System.out.println("每小时赚:$"+time_money);System.out.println("总工资:$"+gross_pay);System.out.println("扣除的钱:");//扣除额System.out.print("联邦扣除额("+LBSLV2+"%): ");System.out.printf("$%1.1f",Federal_Withholding);//格式化输出,保留1位小数//联邦扣除税额保留一位小数,州扣除税额保留两位小数System.out.println();System.out.print("州扣除额("+ZSLV2+"%): ");System.out.printf("$%1.2f",State_Withholding);//格式化输出,保留两位小数System.out.println();System.out.printf("总计扣除额: $%1.2f\n",(Total_Deduction));//格式化输出,保留两位小数,转义符换行System.out.printf("剩余的钱: $%1.2f\n",Last_money);//格式化输出,保留两位小数 。System.out.println();}public static void test9() {System.out.println("第九道练习题");//财务应用程序:计算利息Scanner input = new Scanner(System.in);//创建输入对象System.out.print("收支余额和年百分利率:");double YE = input.nextDouble();double NLLV = input.nextDouble();double LX = YE * (NLLV/1200);//利息计算公式System.out.printf("利息:%1.5f\n",LX);//保留5位小数System.out.println();}public static void test10() {System.out.println("第十道练习题");Scanner input = new Scanner(System.in);//创建输入对象//未来投资金额计算System.out.print("投资额:");double investmentAmount = input.nextDouble();//投资额System.out.print("年度利息:");double monthlyRate = input.nextDouble();//月利息double annuallyInterestRate = monthlyRate / 1200;//年度利息System.out.print("年数:");int numberOfyears = input.nextInt();//输入年数double Future_value = http://www.kingceram.com/post/investmentAmount * Math.pow((1 + annuallyInterestRate),numberOfyears*12);System.out.printf("未来投资额:%1.2f\n",Future_value);System.out.println();}public static void test11() {System.out.println("第十一道练习题");Scanner input = new Scanner(System.in);//创建输入对象System.out.print("请输入体重(磅):");double weight = input.nextDouble();System.out.print("请输入身高(英寸):");double height = input.nextDouble();double Kg = weight * 0.45359237;//磅转换成公斤double metre = height * 0.0254;//英寸转换成米double BMI = Kg / Math.pow(metre,2);System.out.printf("BMI是:%1.4f\n",BMI);System.out.println();}public static void test12() {System.out.println("第十二道练习题");//输入钱和存款月数,计算每个月的余额 。Scanner input = new Scanner(System.in);//创建输入对象System.out.print("请输入每月向银行存的钱($):");double money = input.nextDouble();//输入每月向银行存的钱System.out.print("请输入要存的月数:");int month = input.nextInt();double YLLV = 0.00417;//月利率double sum = 0;//求和初始值为0for(int i=0;i