home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2004 September
/
Chip_2004-09_cd1.bin
/
program
/
java
/
download
/
ArrayTest.java
< prev
next >
Wrap
Text File
|
2004-07-14
|
844b
|
35 lines
public class ArrayTest {
public static void main(String[] args) {
int[] pole = {10, 16, 20, 30}; // deklarace a inicializace pole ctyrmi prvky
System.out.println("pocet prvku pole: " + pole.length);
System.out.println("soucet vsech prvku");
int a = 0;
for (int i = 0; i < pole.length; i ++) {
a += pole[i];
}
System.out.println("soucet hodnot pole: " + a);
System.out.println("soucet kazdeho druheho prvku");
a = 0;
for (int i = 0; i < pole.length; i += 2) {
a += pole[i];
}
System.out.println("soucet hodnot pole: " + a);
System.out.println("soucet prvniho a posledniho prvku");
a = pole[0] + pole[pole.length -1];
System.out.println("soucet hodnot pole: " + a);
}
}