public static void main(String[] args) {
十多年的益阳网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站的优势是能够根据用户设备显示端的尺寸不同,自动调整益阳建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“益阳网站设计”,“益阳网站推广”以来,每个客户项目都认真落实执行。
double amount = 1200;// 消费金额
boolean isTeacherOrOld = true; // 是否有教师资格证或者老人标识
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的基础问题, 主要考察的就是if else的使用.
参考代码如下
public class SearchFrame {
public static void main(String[] args) {
double m=520;
computeMoney(m);
double m1=5000;
computeMoney(m1);
}
//此方法用于计算 折扣 和应付金额
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为实际应付金额
double pay = m*rate;
//注意,输出的时候,日常生活中习惯上, 折扣不是用0.65来表示, 而是6.5表示,所以需要乘10
System.out.println("购物金额:"+m+"\t折扣:"+rate*10+"\t实际应付金额:"+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");
}
}
}