程式有錯誤.跑不出來..急

import javax.swing.*;

public class homework1

{

public static void main(String arg[])

{

String subtotal;

subtotal=JOptionPane.showInputDialog

(null,"Enter a number which is the subtotal輸入小計,ex:10");

int subtotal=Integer.parseInt(subtotal);

String gratuityrate;

gratuityrate=JOptionPane.showInputDialog

(null,"Enter a number which is the gratuity rate輸入服務費率,ex:15");

double gratuityrate=Double.parseDouble(gratuityrate)/100;

int gratuity=subtotal*gratuityrate;

int total=subtotal+(subtotal*gratuityrate);

String output="The gratuity is"+gratuity+"\\nThe total is"+total;

JOptionPane.showMessageDialog(null,output)

}

}

我的程式.一直出現錯誤

它顯示

homework1.java:29:’;’expected

}

^

1error

我有把homework1改掉.但是結果還是一樣...

可以請教一下我到底哪裡出錯了嗎!?

2 Answers

Rating
  • Almond
    Lv 6
    1 decade ago
    Favorite Answer

    import javax.swing.*;public class homework1{public static void main(String arg[]){String subtotal=JOptionPane.showInputDialog(null,"Enter a number which is the subtotal輸入小計,ex:10");int subtotal2=Integer.parseInt(subtotal); //請用不同的變數來儲存轉成int的值,否則會有錯誤訊息。String gratuityrate;gratuityrate=JOptionPane.showInputDialog(null,"Enter a number which is the gratuity rate輸入服務費率,ex:15");double gratuityrate2=Double.parseDouble(gratuityrate)/100; //請用不同的變數來儲存轉成double的值,否則會有錯誤訊息。double gratuity=subtotal2*gratuityrate2; //int*double最後的型態應為double,所以請用double變數來接收。double total=subtotal2+(subtotal2*gratuityrate2); //int+(int*double)最後型態應為duobel,一樣請用double變數來接收。String output="The gratuity is"+gratuity+"\nThe total is"+total;JOptionPane.showMessageDialog(null,output); //這裡少加分號。}}

    Source(s): 自己
  • 1 decade ago

    "JOptionPane.showMessageDialog(null,output)"

    這行(倒數第三行)少了";"

    但是除了這些外

    還有其他的錯誤...

Still have questions? Get your answers by asking now.