[问题] 我的程式哪里有问题?

楼主: 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