








Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!









^ Dopo la creazione, un array ha lunghezza fissata (e non puòcambiare nel programma tramite una nuova dichiarazione). ^ Gli elementi di un array possono essere assegnati ad elementi diun array dello stesso tipo:^ int^ x[]
=^ new^ int[10];int y[] =^ new^ int[50];x[3] = y[5];
int^ vetA[]
=^ new^ int[20]; int^ vetB[]
=^ new^ int[10]; ^ Per copiare la seconda metà di
vetA^ in^ vetB
for(int^ i=0;
i<^ 10;^ i++) vetB[i]^ =
vetA[i+10]; ^ oppure^ for(int
i=10;^ i<
20;^ i++) vetB[i-10]
=^ vetA[i];
vet1^ in^ vet
in ordine
inverso:^ int^ vet1[]
=^ new^ int[20]; int^ vet2[]
=^ new^ int[20]; for(int^ i=0;
i<^ 20;^ i++) vet2[i]^ =
vet1[19-i];
Prima^
Dopo
-^ System.out.println(seq.length);
cercamassimo{ public^ static
void^ main(String
args[])
{ int[]^ seq;int^ max,^
ind; seq^ =^ new
int[10]; for^ (ind=0;
ind^ <^ 10;
ind++) { seq[ind]
=^ Console.readInt("dammi
un^ numero");
} max^ =^ seq[0];for(ind=0;
ind^ <^ 10;
ind++) { if^ (seq[ind]
^ max) max^ =^ seq[ind];} System.out.println
("Massimo
=^ "^ +^ max);
} }
int^ [][]^
Matrice^ =
new^ int[3][5];
(^074273122) -1 (^3315456308)
Matrice[0]Matrice[1]Matrice[2]
Matrice[1][3]
int[][]^
tabella^
=^ new^ int[4][];
^ Assegnamento^ for(int
i=0;^ i<tabella.length;
i++)
tabella[i]
=^ new^ int[i+1];
matrice{...^.^. public^ void^ leggimatrice(){ int[][]^ mat;int^ i,j;mat =^ new^ int[4][5];for (i=0;^ i^ <
4;^ i++) { for(j=0;
j^ <^ 5;^ j++)mat[i][j]=^ Console.readInt("dammi
un^ elemento");