Lernpfad:Objektorientierte Programmierung mit Java/Arrays: Unterschied zwischen den Versionen

Zur Navigation springen Zur Suche springen
keine Bearbeitungszusammenfassung
KKeine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 48: Zeile 48:


Zugriffe mit Indizes außerhalb des gültigen Bereichs (also <code>i < 0</code> oder <code>i > length</code>) produzieren einen [https://docs.oracle.com/javase/7/docs/api/java/lang/ArrayIndexOutOfBoundsException.html Fehler].
Zugriffe mit Indizes außerhalb des gültigen Bereichs (also <code>i < 0</code> oder <code>i > length</code>) produzieren einen [https://docs.oracle.com/javase/7/docs/api/java/lang/ArrayIndexOutOfBoundsException.html Fehler].
{{Aufgabe:Start}}
{| border=1
|rowspan="2"|<syntaxhighlight lang="java">
int[] zahlen = new int[6];
</syntaxhighlight>
!Inhalt
| 0 || 0 || 0 || 0 || 0 || 0
|-
!Index
|<code>0</code> || <code>1</code> || <code>2</code> || <code>3</code>  || <code>4</code>  || <code>5</code>
|}
{| border=1
|rowspan="2"|<syntaxhighlight lang="java">
zahlen[4] = zahlen[4];
</syntaxhighlight>
!Inhalt
| 0 || 0 || 0 || 0 || 4 || 0
|-
!Index
|<code>0</code> || <code>1</code> || <code>2</code> || <code>3</code>  || <code>4</code>  || <code>5</code>
|}
{| border=1
|rowspan="2"|<syntaxhighlight lang="java">
for( int i = 0; i < zahlen.length; i++ ) {
    zahlen[i] = zahlen[2] + i;
}
</syntaxhighlight>
!Inhalt
| 10 || 11 || 12 || 15 || 16 || 17
|-
!Index
|<code>0</code> || <code>1</code> || <code>2</code> || <code>3</code>  || <code>4</code>  || <code>5</code>
|}
{{Aufgabe:End}}


== Über ein Array iterieren ==
== Über ein Array iterieren ==

Navigationsmenü