[問題] 我的程式哪裡有問題?

作者: LawLombie (盧芹達)   2017-10-18 15:46:02
import java.util.*;
public class TrapArea {
public static void main(String[] argv) {
Scanner scan = new Scanner(System.in);
boolean Again = true;
char YN;
double Upper, Lower, Height, Area;
System.out.println("Calculate a trapezoid\'s area");
while (Again == true){
Upper = Lower = Height = Area = 0;
System.out.print("Input the trapezoid\'s upper base(cm):");
Upper = scan.nextDouble(); //The upper base of the trapezoid
System.out.print("\r\nInput the trapezoid\'s lower base(cm):");
Lower = scan.nextDouble(); //The lower base of the trapezoid
System.out.print("\r\nInput the trapezoid\'s height(cm):");
Height = scan.nextDouble(); //The height of the trapezoid
Area = (Upper + Lower) /2 *Height; //The area of the trapezoid
System.out.println("\r\nThe area of the trapezoid is" + Area + "cm2");
System.out.print("Do you want to calculate another trapezoid\'s area?
Input Y or N.");
YN = scan.nextChar();
if (YN == 'N'){
Again = false;
}
}
}
}
作者: LawLombie (盧芹達)   2017-10-18 15:53:00
很抱歉,我可能需要明天才能觀看你們的回覆。因為我明天才能再用電腦。還有,System.out.print裡都是英文,是因為我每次用中文時都會有錯誤。我就靠你們囉。 QQ請回應喔!拜託回答我!
作者: LnZhen (LnZhen)   2017-10-18 16:36:00
Google搜nextchar java就有了
作者: fayhong (恰似飛鴻踏雪泥)   2017-10-18 21:15:00
Scanner應該沒有 nextChar,用 nextLine
作者: LawLombie (盧芹達)   2017-10-20 06:47:00
謝謝 LnZhen 問題解決了
作者: hpbl (頂)   2017-10-23 21:24:00
Again == true 太冗

Links booklink

Contact Us: admin [ a t ] ucptt.com