gegeben ist das folgende programm:
nun soll ich das programm so abaendern, dass die instanzenmethode lieszahl verwendet wird. das hab ich wie folgt gemacht:
so laeuft es auch, aber meine frage ist:
das eingefuegte static oben bezieht sich doch jetzt auf ein objekt. muss ich das jetzt noch erzeugen? in der main?
Java:
public class Aufgabe4 {
//Objektmethode
public int liesZahl () {
int i = util.StdInput.readInt("Ganzzahl eingeben:");
return i;
}
//Klassenmethode
public static void main(String[] args) {
int i= liesZahl(); //int i=liesZahl() eingefuegt
while (true) {
int i = util.StdInput.readInt();
System.out.println(i);
if (i==5) break;
}
}
}
nun soll ich das programm so abaendern, dass die instanzenmethode lieszahl verwendet wird. das hab ich wie folgt gemacht:
Java:
import util.StdInput;
public class Aufgabe4 {
//Objektmethode
public static int liesZahl () { //static eingefuegt
int i = util.StdInput.readInt("Ganzzahl eingeben:");
return i;
}
//Klassenmethode
public static void main(String[] args) {
int i= liesZahl(); //int i=liesZahl() eingefuegt
while (true) {
//int i = util.StdInput.readInt();
System.out.println("eingegebene Zahl:" + " " + i);
if (i==5) break;
}
}
}
das eingefuegte static oben bezieht sich doch jetzt auf ein objekt. muss ich das jetzt noch erzeugen? in der main?