S
Sidarxw
Gast
also mein aufgabe ist einen algorithmus in java darzustellen der so ausschauen muss:
Bei der eingabe von 7:
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 ...
wie schaffe ich dass der programm 1x1; 2x2; 3x3 usw ausgibt???? wenn ich 5 eingebe schreibt mein programm alles 5x...Danke im voraus...
---------------------------------
public class zahlenfolge {
public static void main(String[] args){
int a = 0;
System.out.println("Geben Sie eine Zahl ein: ");
int n = Input.readInt();
do{
a=a+1;
for (int i=1; i <= n; i++){
System.out.print(a);
}
}while (a < n);
}
}
Bei der eingabe von 7:
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 ...
wie schaffe ich dass der programm 1x1; 2x2; 3x3 usw ausgibt???? wenn ich 5 eingebe schreibt mein programm alles 5x...Danke im voraus...
---------------------------------
public class zahlenfolge {
public static void main(String[] args){
int a = 0;
System.out.println("Geben Sie eine Zahl ein: ");
int n = Input.readInt();
do{
a=a+1;
for (int i=1; i <= n; i++){
System.out.print(a);
}
}while (a < n);
}
}
Zuletzt bearbeitet von einem Moderator: