2014.10.15--Java基礎課第二天學習總結

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();
	}
}





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章