2014.10.15--Java基础课第二天学习总结

来源:互联网 发布:做股票网络销售合法吗 编辑:程序博客网 时间:2024/04/29 19:18

1.个人所得税计算器:


<span style="font-size:18px;">package com.hechao;import java.util.Scanner;public class Income {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.print("请输入工资总收入:");double revenue = sc.nextDouble();// 工资System.out.print("请输入五险一金扣除金额:");double secure = sc.nextDouble();// 保险double a = revenue - secure;double duty = 0;if (a > 80000) {duty = (a - 3500) * 0.45 - 13505;} else if (a > 55000 && a <= 80000) {duty = (a - 3500) * 0.35 - 5505;} else if (a > 35000 && a <= 55000) {duty = (a - 3500) * 0.3 - 2755;} else if (a > 9000 && a <= 35000) {duty = (a - 3500) * 0.25 - 1005;} else if (a > 4500 && a <= 9000) {duty = (a - 3500) * 0.2 - 555;} else if (a > 1500 && a <= 4500) {duty = (a - 3500) * 0.03 - 0;} else {duty = 0;}System.out.print("应交个人所得税为:");System.out.printf("%f元", duty);sc.close();}}</span>
<span style="font-size:18px;"><strong style="background-color: rgb(255, 0, 0);">2.英制与公制的相互转换</strong></span>
<pre name="code" class="java"><span style="font-size:18px;">//将类放入com.lovo文件夹下package com.lovo;//调入扫描器import java.util.Scanner;public class Test1 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("英制与公制的相互转换");double a = sc.nextDouble();System.out.println("请选择单位:厘米请输入0,英寸请输入1。");int b = sc.nextInt();if(b==0){System.out.printf("%f厘米=%f英寸",a,a/2.54);}else if(b==1){System.out.printf("%f英寸=%f厘米",a,a*2.54);}else{System.out.println("单位选择有误,请重新运行程序!");}sc.close();}}</span>


<span style="font-size:18px;"><strong style="background-color: rgb(255, 0, 0);">3.用弹窗输入name,再用弹窗输出“你好,name”</strong></span>
<pre name="code" class="java"><span style="font-size:18px;">package com.lovo;import javax.swing.JOptionPane;public class Hello {public static void main(String[] args) {String name = JOptionPane.showInputDialog("请输入你的名字:");JOptionPane.showMessageDialog(null, "你好" + name + "!");}}</span>
4.判断某一年是否为闰年
<span style="white-space:pre"></span><span style="font-size:18px;">四年一闰,百年不闰,四百年又闰。</span>
<span style="font-size:18px;"></span><pre name="code" class="java">package com.lovo;import java.util.Scanner;public class Test3 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);// 调用扫描器int year = sc.nextInt();// 输入年份if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {// 判断既是4的倍数,又不是100的倍数。或者是400的倍数,则是闰年。System.out.println(year+"年是闰年");} else {System.out.println(year+"年不是闰年");}sc.close();}}



0 0
原创粉丝点击