for-schleifen



  • hallo ich soll in einem java programm mittels for-schleifen folgende ausgaben erzeugen: (wenn ich es richtig verstanden habe)
    da ich c++ schon besser beherrsche habe ich es hierhin gepostet da es in c++ identsich aussieht
    0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0
    Abbildung 2: Variante 1: Nullmatrix
    0
    0 0
    0 0 0
    0 0 0 0
    0 0 0 0 0
    Abbildung 3: Variante 2: linke untere Dreiecksmatrix
    0 0 0 0 0
    0 0 0 0
    0 0 0
    0 0
    0
    Abbildung 4:

    dies soll mittels zweier for-schleifen geschehen der anwesung break und continue
    nunja lösung habe ich bereits:

    #include <iostream>
    
    using namespace std;
    
    void printDefaultMatrix();
    void printLeftUpperMatrix();
    void printRightLowerMatrix();
    
    int main()
    {
        printDefaultMatrix();
        cout << endl;
        printLeftUpperMatrix();
        cout << endl;
        printRightLowerMatrix();
    }
    
    void printDefaultMatrix()
    {
        int i,j;
    
        for(i=0; i<5; i++)
        {
            for(j=0; j<5; j++)
            {
                cout << "0 ";
            }
            cout << endl;
        }
    }
    
    void printLeftUpperMatrix()
    {
        int i,j;
    
        for(i=0; i<5; i++)
        {
            for(j=1; j<=5; j++)
            {
                if( j<=i)
                    continue;
                cout << "0 ";
            }
            cout << endl;
        }
    }
    
    void printRightLowerMatrix()
    {
        int i,j;
    
        for(i=0; i<5; i++)
        {
            for(j=1; j<=5; j++)
            {
                if( j<=i)
                    continue;
                cout << "0 ";
            }
            cout << endl;
        }
    }
    

    meine frage wieso funktioniert das so??
    ich habs eher experimentell bestimmt die mit 25 nullen war kein problem aber der rest war eher so: ich geb ein und schau was passiert



  • Spezifizier mal deine Frage!


Anmelden zum Antworten