剛學習異常捕獲。這會產生「高度無法解析爲變量」。我想我錯過了一些至關重要的事情。在try塊內聲明的變量無法解析
import java.util.*;
public class Step4_lab01
{
public static void main(String[] args)
{
Scanner userIn = new Scanner(System.in);
System.out.print("Input height: ");
try {
int height = userIn.nextInt();
}
catch(InputMismatchException e)
{
System.out.println("ERORRORrr");
}
System.out.print("Input width: ");
int width = userIn.nextInt();
Rectangle rektangel1 = new Rectangle(height,width);
rektangel1.computeArea();
}
}
好主意!代碼雖然不適用於我。我被困在一個無限的「高度必須在數字中,再試一次!」循環。 –
@BenjaminLindqvist:是的,我的錯誤看到編輯答案。 – Azad