import java.util.Scanner;
public class Lab2{
public static void main(String args[]){
System.out.println("請輸入購物金額");
Scanner keyin = new Scanner(System.in);
int charge = keyin.nextInt();
if (charge < 2000){
int fee = (int)(charge*0.95);
System.out.println("你的金額是:"+charge+",打折後為 "+fee);
}else if(charge <3000){
int fee = (int)(charge*0.9);
System.out.println("你的金額是:"+charge+",打折後為 "+fee);
}else if(charge < 4000){
int fee = (int)(charge*0.85);
System.out.println("你的金額是:"+charge+",打折後為 "+fee);
}else if(charge < 5000){
int fee = (int)(charge*0.8);
System.out.println("你的金額是:"+charge+",打折後為 "+fee);
}else{
int fee = (int)(charge*0.75);
System.out.println("你的金額是:"+charge+",打折後為 "+fee);
}
}
}
//######### source code ends #########################
2009年1月14日 星期三
Java小練習(2)
某百貨公司舉行週年慶,給消費者的折扣為:購物金額小於2000元打九五折,購物金額滿2000元打九折,滿3000元打八五折,,滿4000元打八 折,滿5000元打七五折。
請撰寫一程式,輸入一購物金額,輸出打折後的需付金額。
看來用簡單的if else就可以解決。
//######## source code starts from here #################
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言