day4作業-------Java基礎班

練習題

1.編寫代碼實現如下內容:if語句實現考試成績分等級(使用switch語句)。

[90-100]	A等。
[80-90) 	B等。
[70-80) 	C等。
[60-70) 	D等。
[0-60)  	E等。
請根據給定成績,輸出對應的等級。
說明:"["表示包含,")"表示不包含
/*1.編寫代碼實現如下內容:if語句實現考試成績分等級(使用switch語句)。
	[90-100]	A等。
	[80-90) 	B等。
	[70-80) 	C等。
	[60-70) 	D等。
	[0-60)  	E等。
	請根據給定成績,輸出對應的等級。
	說明:"["表示包含,")"表示不包含
*/
import java.util.Scanner;
public class ChengJidemo{
	public static void main(String[] args){
		System.out.println("請輸入您的成績: ");
		Scanner s = new Scanner(System.in);
		double Grade = s.nextDouble();
		
		if(Grade >= 90){
			System.out.println("成績A等");
		}else if(Grade >= 80){
			System.out.println("成績B等");
		}else if(Grade >= 70){
			System.out.println("成績C等");
		}else if(Grade >= 60){
			System.out.println("成績D等");
		}else {
			System.out.println("成績E等");
		}
		
	}
}	

在這裏插入圖片描述

2.分析以下需求,並用代碼實現:

(1)根據工齡(整數)給員工漲工資(整數),工齡和基本工資通過鍵盤錄入
(2)漲工資的條件如下:
	[10-15)     +5000
	[5-10)      +2500
	[3~5)       +1000
	[1~3)       +500
	[0~1)       +200
(3)如果用戶輸入的工齡爲10,基本工資爲3000,程序運行後打印格式"您目前工作了10年,基本工資爲 3000元, 應漲工資 5000元,漲後工資 8000元"
/*
	(1)根據工齡(整數)給員工漲工資(整數),工齡和基本工資通過鍵盤錄入
	(2)漲工資的條件如下:
		[10-15)     +5000
		[5-10)      +2500
		[3~5)       +1000
		[1~3)       +500
		[0~1)       +200
	(3)如果用戶輸入的工齡爲10,基本工資爲3000,程序運行後打印格式
	"您目前工作了10年,基本工資爲 3000元, 應漲工資 5000元,漲後工資 8000元"
*/

import java.util.Scanner;
public class GongZiDemo{
	public static void main(String[] args){
		System.out.println("請輸入您的工齡: ");
		Scanner i = new Scanner(System.in);
		int years = i.nextInt();
		
		System.out.println("請輸入您的基本工資: ");
		Scanner s = new Scanner(System.in);
		double money = s.nextDouble();
		if(money < 0){
			System.out.println("您的輸入有誤");
		}
		
		if(years >= 10){
			double moneys = money+5000;
			System.out.println("您目前工作了 "+years+"年,基本工資爲 "+money+"元, 應漲工資 5000元,漲後工資 "+moneys+"元");
		}else if(years >= 5){
			double moneys = money+5000;
			System.out.println("您目前工作了 "+years+"年,基本工資爲 "+money+"元, 應漲工資 2500元,漲後工資 "+moneys+"元");
		}else if(years >= 3){
			double moneys = money+5000;
			System.out.println("您目前工作了 "+years+"年,基本工資爲 "+money+"元, 應漲工資 1000元,漲後工資 "+moneys+"元");
		}else if(years >= 1){
			double moneys = money+5000;
			System.out.println("您目前工作了 "+years+"年,基本工資爲 "+money+"元, 應漲工資 500元,漲後工資 "+moneys+"元");
		}else if(years >= 0){
			double moneys = money+5000;
			System.out.println("您目前工作了 "+years+"年,基本工資爲 "+money+"元, 應漲工資 200元,漲後工資 "+moneys+"元");
		}else{
			System.out.println("您的輸入有誤");
		}
	}
}

在這裏插入圖片描述
老師代碼:

public class Demo5 {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		// 鍵盤錄入
		System.out.println("請輸入工齡:");
		int service = Integer.parseInt(new Scanner(System.in).next());
		System.out.println("請輸入基本工資");
		int basePay = Integer.parseInt(new Scanner(System.in).next());
		if (service >= 10 && service < 15) {
			basePay += 5000;
		}else if (service >= 5 && service < 10){
			basePay += 2500;
		}else if (service >= 3 && service < 5){
			basePay += 1000;
		}else if (service >= 1 && service < 3){
			basePay += 500;
		}else if (service >= 0 && service < 1){
			basePay += 200;
		}else{
			System.out.println("出現錯誤");
		}
		System.out.println("工齡爲"+service+"年\t最後工資爲"+basePay+"元");
	}
}

3.分析以下需求,並用代碼實現:

(1)鍵盤錄入三個整數,按照從小到大的順序輸出
(2)如果用戶輸入的是3 2 1,程序運行後打印格式"按照從小到大排序後的順序爲:1 2 3"
/*
	(1)鍵盤錄入三個整數,按照從小到大的順序輸出
	(2)如果用戶輸入的是3 2 1,程序運行後打印格式"按照從小到大排序後的順序爲:1 2 3"
*/

import java.util.Scanner;
public class PaiXuDemo{
	public static void main(String[] args){
	System.out.println("請輸入三個整數: ");
	
	Scanner s = new Scanner(System.in);
	int a =s.nextInt();
	int b = s.nextInt();
	int c = s.nextInt();
	
	if(a>b){
		if(b>c){
			System.out.println("按照從小到大排序後的順序爲:"+c+" "+b+" "+a+" ");
		}else if(a>c){
			System.out.println("按照從小到大排序後的順序爲:"+b+" "+c+" "+a+" ");
		}else{
			System.out.println("按照從小到大排序後的順序爲:"+b+" "+a+" "+c+" ");
		}
	}else{
		if(a>c){
			System.out.println("按照從小到大排序後的順序爲:"+c+" "+a+" "+b+" ");
		}else if(b>c){
			System.out.println("按照從小到大排序後的順序爲:"+a+" "+c+" "+b+" ");
		}else{
			System.out.println("按照從小到大排序後的順序爲:"+a+" "+c+" "+b+" ");
		}
	}
	}
}

在這裏插入圖片描述
做作業好累!!!!!!
老師代碼:

public class Demo2 {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		String str[] = new Scanner(System.in).nextLine().split(" ");
		int a = Integer.valueOf(str[0]), b = Integer.valueOf(str[1]), c = Integer.valueOf(str[2]);
		System.out.println(Math.min(Math.min(a, b), c) + " "
				+ (a > Math.min(Math.min(a, b), c) && a < Math.max(Math.max(a, b), c) ? a
						: b > Math.min(Math.min(a, b), c) && b < Math.max(Math.max(a, b), c) ? b
								: c > Math.min(Math.min(a, b), c) && c < Math.max(Math.max(a, b), c) ? c : 0)
				+ " " + Math.max(Math.max(a, b), c));
	}
}


看不懂!!

編寫過程中常見錯誤

1.因爲經常要打印漢字,中英文分號能把我搞死1
2.主方法好像今天沒寫對過,我真的是一個一個對比DOS窗口提示的查看過,我的一點問題沒有,但就是編譯可以,不能運行。到現在沒搞懂!!
在這裏插入圖片描述解決辦法:粘貼複製DOS命令中的
public static void main(String[] args)
成功!!

寫作業真累,啊啊啊啊

不過看明天要學類了,有點小期待。

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