JAVA求大神帮忙看看怎么弄?
importjava.util.Scanner;publicclassshengji{/***@paramargs*/publicstaticvoidmain(Strin...
import java.util.Scanner;
public class shengji {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
while(true){
System.out.println("请选择购买的商品编号:1.T恤2.网球鞋3.网球拍");
int num=input.nextInt();
System.out.println("请选择购买数量:");
int b=input.nextInt();
switch (num) {
case 1:
double money1=245.0;
System.out.println("T恤¥"+money1+"\t"+"数量:"+b+"\t"+"合计:"+money1*b);
break;
case 2:
double money2=570.0;
System.out.println("网球鞋¥"+money2+"\t"+"数量:"+b+"\t"+"合计:"+money2*b);
break;
case 3:
double money3=1000.0;
System.out.println("网球拍¥"+money3+"\t"+"数量:"+b+"\t"+"合计:"+money3*b);
break;
default:
System.out.println("选择错误,重新选择");
break;
}
System.out.println("是否继续y/n");
String str=input.next();
if(str.equals("n")){
System.out.println("折扣:0.8");
System.out.println("应付金额:");
System.out.println("实付金额:");
int Smoney=input.nextInt();
System.out.println("找钱:"+Smoney);
}
}
}
}
应付金额应该怎么写? 展开
public class shengji {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
while(true){
System.out.println("请选择购买的商品编号:1.T恤2.网球鞋3.网球拍");
int num=input.nextInt();
System.out.println("请选择购买数量:");
int b=input.nextInt();
switch (num) {
case 1:
double money1=245.0;
System.out.println("T恤¥"+money1+"\t"+"数量:"+b+"\t"+"合计:"+money1*b);
break;
case 2:
double money2=570.0;
System.out.println("网球鞋¥"+money2+"\t"+"数量:"+b+"\t"+"合计:"+money2*b);
break;
case 3:
double money3=1000.0;
System.out.println("网球拍¥"+money3+"\t"+"数量:"+b+"\t"+"合计:"+money3*b);
break;
default:
System.out.println("选择错误,重新选择");
break;
}
System.out.println("是否继续y/n");
String str=input.next();
if(str.equals("n")){
System.out.println("折扣:0.8");
System.out.println("应付金额:");
System.out.println("实付金额:");
int Smoney=input.nextInt();
System.out.println("找钱:"+Smoney);
}
}
}
}
应付金额应该怎么写? 展开
1个回答
展开全部
定义一个sum,在每个case语句后面赋值, ,然后sum=sum*0.8 ,最后引用就可以了
import java.util.Scanner;
public class shengji {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
double sum=0;
while(true){
System.out.println("请选择购买的商品编号:1.T恤2.网球鞋3.网球拍");
int num=input.nextInt();
System.out.println("请选择购买数量:");
int b=input.nextInt();
switch (num) {
case 1:
double money1=245.0;
sum=money1*b;
System.out.println("T恤¥"+money1+"\t"+"数量:"+b+"\t"+"合计:"+sum);
break;
case 2:
double money2=570.0;
sum=money2*b;
System.out.println("网球鞋¥"+money2+"\t"+"数量:"+b+"\t"+"合计:"+sum);
break;
case 3:
double money3=1000.0;
sum=money3*b;
System.out.println("网球拍¥"+money3+"\t"+"数量:"+b+"\t"+"合计:"+sum);
break;
default:
System.out.println("选择错误,重新选择");
break;
}
System.out.println("是否继续y/n");
String str=input.next();
if(str.equals("n")){
System.out.println("折扣:0.8");
sum=sum*0.8;
System.out.println("应付金额:"+sum);
System.out.println("实付金额:");
int Smoney=input.nextInt();
System.out.println("找钱:"+Smoney);
}
}
}
}
import java.util.Scanner;
public class shengji {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
double sum=0;
while(true){
System.out.println("请选择购买的商品编号:1.T恤2.网球鞋3.网球拍");
int num=input.nextInt();
System.out.println("请选择购买数量:");
int b=input.nextInt();
switch (num) {
case 1:
double money1=245.0;
sum=money1*b;
System.out.println("T恤¥"+money1+"\t"+"数量:"+b+"\t"+"合计:"+sum);
break;
case 2:
double money2=570.0;
sum=money2*b;
System.out.println("网球鞋¥"+money2+"\t"+"数量:"+b+"\t"+"合计:"+sum);
break;
case 3:
double money3=1000.0;
sum=money3*b;
System.out.println("网球拍¥"+money3+"\t"+"数量:"+b+"\t"+"合计:"+sum);
break;
default:
System.out.println("选择错误,重新选择");
break;
}
System.out.println("是否继续y/n");
String str=input.next();
if(str.equals("n")){
System.out.println("折扣:0.8");
sum=sum*0.8;
System.out.println("应付金额:"+sum);
System.out.println("实付金额:");
int Smoney=input.nextInt();
System.out.println("找钱:"+Smoney);
}
}
}
}
追问
这样sum下会有红线,会报错
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询