看板 java 關於我們 聯絡資訊
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; } } } } ----------------------------------------------------------------------------- 如上 我在編譯它時,會跳出 https://imgur.com/NdRqQZG 請問要如何修改呢??? (第一次發文) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.243.2.30 ※ 文章網址: https://www.ptt.cc/bbs/java/M.1508312764.A.9CE.html
LawLombie: 很抱歉,我可能需要明天才能觀看你們的回覆。 10/18 15:53
LawLombie: 因為我明天才能再用電腦。 10/18 15:54
LawLombie: 還有,System.out.print裡都是英文,是因為我每次用中 10/18 15:56
LawLombie: 文時都會有錯誤。 10/18 15:58
LawLombie: 我就靠你們囉。 QQ 10/18 15:59
LawLombie: 請回應喔! 10/18 16:01
LawLombie: 拜託回答我! 10/18 16:18
LnZhen: Google搜nextchar java就有了 10/18 16:36
fayhong: Scanner應該沒有 nextChar,用 nextLine 10/18 21:15
LawLombie: 謝謝 LnZhen 問題解決了 10/20 06:47
hpbl: Again == true 太冗 10/23 21:24