Ich weiß nicht was falsch ist ich die rechnungen sind immer um 1 falsch
}
[CODE lang="java" title="SquareWithWhile"]import java.util.*;
public class SquareWithWhile //erstellt von:
//erstellt am: 23.11.2020
//Beschreibung:Quadriert
{
public static void main(String args[]) ///Starten mit der Methode main
{
int zahl = 1; // Der Variable "zahl" wird der Wert 1 hinzugefügt
while(zahl < 10) // while wird eingesetzt
{
int ergebnis=zahl * zahl; //Rechnet zahl mal zahl
zahl += 1;
System.out.printf("%d^2 =%d%n",zahl, ergebnis);
}
/*Scanner sc = new Scanner(System.in); //Scanner wird eingesetzt
System.out.println("Geben sie eine Zahl an"); //Man soll eine Zahl eingeben
int zahl2 = sc.nextInt();
int zahl3= 0; // Der Variable "zahl3" wird der Wert 0 gegeben
while(zahl3 <=zahl2) //while wird eingesetzt
{
int ergebnis = zahl3 * zahl3; //Gibt das Ergebnis
zahl3 += 1;
System.out.printf("%d%n", ergebnis);
}*/
}
}[/CODE]
}
[CODE lang="java" title="SquareWithWhile"]import java.util.*;
public class SquareWithWhile //erstellt von:
//erstellt am: 23.11.2020
//Beschreibung:Quadriert
{
public static void main(String args[]) ///Starten mit der Methode main
{
int zahl = 1; // Der Variable "zahl" wird der Wert 1 hinzugefügt
while(zahl < 10) // while wird eingesetzt
{
int ergebnis=zahl * zahl; //Rechnet zahl mal zahl
zahl += 1;
System.out.printf("%d^2 =%d%n",zahl, ergebnis);
}
/*Scanner sc = new Scanner(System.in); //Scanner wird eingesetzt
System.out.println("Geben sie eine Zahl an"); //Man soll eine Zahl eingeben
int zahl2 = sc.nextInt();
int zahl3= 0; // Der Variable "zahl3" wird der Wert 0 gegeben
while(zahl3 <=zahl2) //while wird eingesetzt
{
int ergebnis = zahl3 * zahl3; //Gibt das Ergebnis
zahl3 += 1;
System.out.printf("%d%n", ergebnis);
}*/
}
}[/CODE]