剛幫你調(diào)測(cè)了一下,當(dāng)你輸入"n"的時(shí)候,已經(jīng)跳出循環(huán)了,只不過(guò)你沒(méi)有輸出提示,以為沒(méi)出來(lái),
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專(zhuān)注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、小程序設(shè)計(jì)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了彰武免費(fèi)建站歡迎大家使用!
又輸入字符了所有報(bào)錯(cuò)了,應(yīng)該是輸入金額的,我?guī)湍慵恿讼螺敵瞿憧梢钥聪陆Y(jié)果;
public static void main(String args[]){
System.out.println("********************");
System.out.println("");
System.out.println("請(qǐng)選擇購(gòu)買(mǎi)商品編號(hào):");
System.out.println("1.T恤(¥245.0) 網(wǎng)球鞋(¥570.0) 網(wǎng)球拍(¥500.0)");
System.out.println("********************");
System.out.println("");
double s=0;
String d;
do{
System.out.println("請(qǐng)輸入商品編號(hào):");
Scanner input=new Scanner(System.in);
int a=input.nextInt();
if(a==1){
System.out.println("請(qǐng)輸入購(gòu)買(mǎi)數(shù)量:");
int b=input.nextInt();
double c=245*b;
System.out.println("T恤¥245.0 數(shù)量:"+b+" "+"合計(jì):"+c);
s=s+c;
}
else if(a==2){
System.out.println("請(qǐng)輸入購(gòu)買(mǎi)數(shù)量:");
int b=input.nextInt();
double c=570*b;
System.out.println("網(wǎng)球鞋¥245.0 數(shù)量:"+b+" "+"合計(jì):"+c);
s=s+c;
}
else if(a==3){
System.out.println("請(qǐng)輸入購(gòu)買(mǎi)數(shù)量:");
int b=input.nextInt();
double c=500*b;
System.out.println("網(wǎng)球拍¥245.0 數(shù)量:"+b+" "+"合計(jì):"+c);
s=s+c;
}
else {System.out.println("無(wú)此商品");}
System.out.println("否繼續(xù)(y/n)");
d=input.next();
}while(d.equals("y"));
System.out.println("===========付款===========");
System.out.println("=====輸入金額=====");
Scanner input=new Scanner(System.in);
int x=input.nextInt();
double m=s*0.8;
System.out.println("折扣:0.8");
System.out.println("應(yīng)付金額:"+m);
System.out.println("實(shí)際金額:"+x);
double p=x-m;
System.out.println("找錢(qián):"+p);
}
html
head
meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"
title購(gòu)物與結(jié)算/title
style?type="text/css"
/style
link?rel="stylesheet"?href="
script?src="
script?src="
script?src="
script?src="
(beta4)/IE9.js"/script
script?src="?
script?type="text/javascript"
function?pay()
{
var?link?=?document.getElementById("a1");
link.click();
var?a?=?new?Array();
a[0]="html教程";
a[1]=12;
a[2]=1;
a[3]=a[1]*a[2];
var?a1?=?new?Array();
a1[0]="java詳解";
a1[1]=25;
a1[2]=2;
a1[3]=a1[1]*a1[2];
var?b?=?new?Array();
b[0]=a;
b[1]=a1;
var?amount?=0;
for(var?i=0;ib.length;i++)
{
var?c?=?new?Array();
c=b[i];
amount?=?amount+c[3];
var?tr?="tr";
for(var?j=0;jc.length;j++)
{
tr+="td"+c[j]+"/td";
}
tr+="/tr";
$("#list").append(tr);
$("#all").html("b總計(jì):/bfont?color=\"red\""+amount+"/font")
}
}
function?goon()
{
var?link?=?document.getElementById("a2");
link.click();
$("#news").html("支付成功!!");
}
/script
/head
body
input?type="button"?class="btn?btn-danger"?value="點(diǎn)擊結(jié)算"?onclick="pay()"
a?href="#myModaltishi"?role="button"?class="btn"?data-toggle="modal"?id="a1"?style="display:?none"/a?
div?id="myModaltishi"?class="modal?hide?fade"?tabindex="-1"?role="dialog"?aria-labelledby="myModalLabel"?aria-hidden="true"??
div?class="modal-header"??
button?type="button"?class="close"?data-dismiss="modal"?aria-hidden="true"×/button??
h3?id="myModalLabel"購(gòu)物車(chē)/h3??
/div??
div?class="modal-body"??
div
table?id="list"?style="width:?95%;"?class="table"
th商品名稱(chēng)/th
th單價(jià)/th
th數(shù)量/th
th金額/th
/table
/div
div?align="right"?id="all"/div
/div??
div?class="modal-footer"??
button?class="btn"?data-dismiss="modal"?aria-hidden="true"繼續(xù)挑選/button??
button?class="btn?btn-primary"?data-dismiss="modal"?onclick="goon()"支付/button??
/div??
/div?
a?href="#myModaltishi1"?role="button"?class="btn"?data-toggle="modal"?id="a2"?style="display:?none"/a?
div?id="myModaltishi1"?class="modal?hide?fade"?tabindex="-1"?role="dialog"?aria-labelledby="myModalLabel"?aria-hidden="true"??
div?class="modal-header"??
button?type="button"?class="close"?data-dismiss="modal"?aria-hidden="true"×/button??
h3?id="myModalLabel"系統(tǒng)提示/h3??
/div??
div?class="modal-body"??
h3?id="news"?align="center"/h3
/div??
div?class="modal-footer"??
button?class="btn?btn-primary"?data-dismiss="modal"知道了/button??
/div??
/div?
/body
!--?瀏覽器打開(kāi)可查看效果,
另外由于頁(yè)面使用了bootstrap框架建議使用渲染較高的瀏覽器,例如:火狐?--
/html
2、public class Test11 {
public static void main(String[] args) {
System.out.println("滯貿(mào)旅客的人數(shù)" + (1189 - 108*10) );
}
}
3、public class Test11 {
public static void main(String[] args) {
try {
Scanner scanner = new Scanner(System.in);
System.out.print("輸入購(gòu)買(mǎi)雞蛋(斤):");
int number = scanner.nextInt();
if(number10){
throw new RuntimeException("不允許購(gòu)買(mǎi)這么多!");
}
else {
System.out.println("用戶應(yīng)支付金額"+number*3.98);
}
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
}
你也不說(shuō)計(jì)算公式,不知道怎么計(jì)算,我去網(wǎng)上找了一個(gè)月支付款的計(jì)算公式,不知道和你題目的要求是否一樣,如果不一樣你就改下公式就行。
java代碼如下:
public?class?Loan?{
public?static?void?main(String[]?args){
double?rate?;//利率
int?year?;?//年數(shù)
double?money?;?//貸款總額
double?monthpay?;//月付款
Scanner?sc?=?new?Scanner(System.in);
System.out.println("輸入月利率:");
rate?=?sc.nextDouble();
System.out.println("輸入年數(shù):");
year?=?sc.nextInt();
System.out.println("輸入貸款總額:");
money?=?sc.nextDouble();
//計(jì)算月付款
monthpay?=?(money?*?rate)/Math.abs(1?-?(1?/?(1?+?rate?)?*?year?*?12?));
System.out.println("每月應(yīng)該還貸款:"?+?monthpay);
}
}