public static void main(String[] args) {
十多年的益陽網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。營銷型網(wǎng)站的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整益陽建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)公司從事“益陽網(wǎng)站設(shè)計”,“益陽網(wǎng)站推廣”以來,每個客戶項目都認(rèn)真落實執(zhí)行。
double amount = 1200;// 消費金額
boolean isTeacherOrOld = true; // 是否有教師資格證或者老人標(biāo)識
BigDecimal discountEightFive = new BigDecimal("0.85");// 85折
BigDecimal discountNine = new BigDecimal("0.9");// 95折
BigDecimal discountNineFive = new BigDecimal("0.95");// 95折
BigDecimal bdAmount = new BigDecimal(Double.toString(amount));
BigDecimal calcAmount = new BigDecimal("0.00");
if (amount = 2000) {
calcAmount = bdAmount.multiply(discountEightFive);
} else if (amount 1000 amount 2000) {
calcAmount = bdAmount.multiply(discountNine);
} else {
calcAmount = new BigDecimal(Double.toString(amount));
}
if (isTeacherOrOld amount = 1000) {
System.out.println("消費金額:" + calcAmount.multiply(discountNineFive).toString());
} else {
System.out.println("消費金額:" + calcAmount.toString());
}
}
這是java的基礎(chǔ)問題, 主要考察的就是if else的使用.
參考代碼如下
public?class?SearchFrame?{
public?static?void?main(String[]?args)?{
double?m=520;
computeMoney(m);
double?m1=5000;
computeMoney(m1);
}
//此方法用于計算?折扣?和應(yīng)付金額
public?static?void?computeMoney(double?m)?{//?m為購物金額
double?rate?=?1.0;//?rate代表折扣率;初始折扣率是
if?(m?=?5000)?{
rate?=?0.65;
}?else?if?(m?=?1000)?{
rate?=?0.7;
}?else?if?(m?=?500)?{
rate?=?0.8;
}?else?if?(m?=?200)?{
rate?=?0.9;
}
//?pay為實際應(yīng)付金額
double?pay?=?m*rate;
//注意,輸出的時候,日常生活中習(xí)慣上,?折扣不是用0.65來表示,?而是6.5表示,所以需要乘10
System.out.println("購物金額:"+m+"\t折扣:"+rate*10+"\t實際應(yīng)付金額:"+pay);
}
}
boolean user=true;
double jg=100;
int xfcount;
三個變量自己決定
if(user){
jg*0.9;
}
if(user==falsexfcount200){
jg*0.9;
}
if(user==truexfcount200){
jg*0.8;
}
嘗試解答一下,這個里面還有老年和教師的判斷就省略,主要是打折的代碼
import?java.util.Scanner;
class?Test{
public?static?void?main?(String[]?args){
Scanner?sc?=?new?Scanner(System.in);
System.out.println("請輸入消費的金額:");
double?oldprice?=?sc.nextDouble();
double?newprice;
if(oldprice?=?2000){
newprice?=?oldprice?*?0.85;
}else?if(oldprice?=?1000??oldprice??2000){
newprice?=?oldprice?*?0.9;
}else
newprice?=?oldprice;
Judge?jud?=?new?Judge();
if(jud.isTeacher()||?jud.isOldman())
newprice?=?newprice?*?0.95;
System.out.println("打折后的價格是:"?+?newprice);
System.out.println("折扣的程度是:?"?+?newprice?/?oldprice);
}
}
class?Judge{
public?boolean?isTeacher(){
boolean?isTeacher?=?false;
return?isTeacher;
}
public?boolean?isOldman(){
boolean?isOld?=?false;
return?isOld;
}
}
public?static?void?main(String[]?args)?{
Scanner?sc?=?new?Scanner(System.in);?//?從控制臺輸入
int?jf?=?sc.nextInt();
if?(jf??2000)
System.out.println("0.9折");
else?if?(jf?=?2000??jf??4000)
System.out.println("0.8折");
else?if?(jf?=?4000??jf??8000)
System.out.println("0.7折");
else
System.out.println("0.6折");
}
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
System.out.println("請輸入會員積分:");
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
sc.close();
if(a200){
System.out.println("該會員享受的折扣是:0.9");
}else if(a=2000a=4000){
System.out.println("該會員享受的折扣是:0.8");
}else if(a=4000a=8000){
System.out.println("該會員享受的折扣是:0.7");
}else if(a=8000){
System.out.println("該會員享受的折扣是:0.6");
}
}
}