home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2004 September
/
Chip_2004-09_cd1.bin
/
program
/
java
/
download
/
ArrayTest2.java
< prev
next >
Wrap
Text File
|
2004-07-14
|
2KB
|
99 lines
import java.io.*;
public class ArrayTest2 {
public static void main(String[] args) throws IOException {
int operace;
char o;
System.out.println("Kolik znaku chcete pouzit?");
System.out.println("a = 3");
System.out.println("b = 5");
char a = (char) System.in.read();
int b = 3;
switch(a) {
case 'a':
b = 3;
break;
case 'b':
b = 5;
break;
}
int[] cisla = new int[b];
for (int i = 0; i < cisla.length; i ++) {
System.out.print("Zadejte znak: ");
cisla[i] = System.in.read();
}
boolean end = false;
do {
System.out.println("Jakou operaci pozadujete?");
System.out.println("a = scitani");
System.out.println("b = nasobeni");
System.out.println("c = vypsani jednotlivych cisel");
System.out.println("z = ukonceni programu");
o = (char) System.in.read();
if (o == 'a') {
int soucet = 0;
for (int i = 0; i < cisla.length; i ++) {
soucet += cisla[i];
}
System.out.println("Soucet cisel je " + soucet);
} else if (o == 'b') {
int soucin = 0;
for (int i = 0; i < cisla.length; i ++) {
soucin *= cisla[i];
}
System.out.println("Soucin cisel je " + soucin);
} else if (o == 'c') {
System.out.println("Pole obsahuje nasledujici cisla:");
for (int i = 0; i < cisla.length; i ++) {
System.out.print(cisla[i] + ", ");
}
} else if (o == 'z') {
end = true;
}
} while (! end);
}
}