sorry brauche hilfe was ist der Fehler der mir hier angezeigt wird
Das hier ist der Code:
Das hier ist der Code:
Java:
import java.util.Scanner;
public class Harmon {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Bitte geben Sie eine Zahl ein: ");
double zahl = scan.nextDouble();
System.out.print("Anzahl Iterationen: ");
double iteration = scan.nextDouble();
double zwischenzahl = zahl;
for(int n=1; n<iteration+1; n++)
{
double Ergebnis = (zwischenzahl + zahl/zwischenzahl)/2;
Ergebnis = (double)Math.round(Ergebnis*100000)/100000;
String text = Double.toString(Ergebnis);
text = text.replace(".", ",");
int counter=0;
while(text.charAt(counter)!=',')
{
counter++;
}
for(int u=0;u<3+counter;u++)
{
text = text+"0";
}
System.out.print(n+". ");
for(int o=0;o<6+counter;o++)
{
System.out.print(text.charAt(o));
}
System.out.println();
zwischenzahl = Ergebnis;
}
scan.close();
}
}
Anhänge
Zuletzt bearbeitet von einem Moderator: