的任务是“变”下面的程序,以便它可以创建一个子类,可以使用户通过扫描仪输入数字:错误:无法找到符号 - 方法liesInt()
public class Patrick3 {
static public void main(String[] emil) throws java.io.IOException {
System.out.println("Jetzt geht es los! Geben sie eine Zahl ein");
while (true) {
System.out.println("Zum Beenden bitte 0 eingeben: ");
int n = EM.liesInt();
if (n == 0) break;
if (n < 0) {
System.out.println("Die Zahl " + n + " ist zu klein!");
continue;
}
BigInteger erg = new BigInteger("1");
BigInteger faktor = new BigInteger("1");
for (int i=1; i < n; i++) {
faktor = faktor.add(BigInteger.ONE);
erg = erg.multiply(faktor);
}
String ergString = erg.toString();
System.out.println("Die Fakultaet von " + n + " ist gleich: ");
System.out.println(ergString);
int laengeD = ergString.length();
int laengeB = erg.bitLength();
System.out.println("Länge (in Dezimalziffern) : " + laengeD);
System.out.println("Länge (in Binaerziffern) : " + laengeB);
} // while
System.out.println("Das war's erstmal!");
}
}
我想这样的:
public class Patrick_3 extends EM {
static public int liesInt() throws IOException {
System.out.println("Jetzt geht es los! Geben sie eine Zahl ein");
while (true) {
System.out.println("Zum Beenden bitte 0 eingeben: ");
int n = EM.liesInt();
}
public class EM
{
public static void main (String [] args)
{
int i;
boolean has_input_int;
boolean isValid_int = false;
String input = "";
Scanner keyboard = new Scanner(System.in); //Decl. & int. a scanner.
do {
System.out.print("Geben Sie eine Int Zahl ein! ");
while (!keyboard.hasNextInt()) {
System.out.println("Fehler! Falsche Eingabe Versuchen sie es nochmals!");
keyboard.next();
}
i = keyboard.nextInt();
isValid_int = true;
} while (isValid_int == false);
}
}
但它说
cannot find symbol - method liesint()
问题出在哪里?
你能下来减少这种代码,以再现错误的绝对最低?见[mcve] –
对不起。当然! – Phoney
什么是EM?错误消息涉及的代码行是什么? –