home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 September / Chip_2004-09_cd1.bin / program / java / download / ArrayTest2.java < prev    next >
Text File  |  2004-07-14  |  2KB  |  99 lines

  1. import java.io.*;
  2.  
  3. public class ArrayTest2 {
  4.  
  5.        public static void main(String[] args) throws IOException {
  6.                  
  7.               int operace;
  8.               char o;          
  9.               
  10.               System.out.println("Kolik znaku chcete pouzit?");
  11.               System.out.println("a = 3");
  12.               System.out.println("b = 5");
  13.  
  14.               char a = (char) System.in.read();
  15.  
  16.               int b = 3;
  17.  
  18.               switch(a) {
  19.  
  20.                 case 'a':
  21.  
  22.                     b = 3;
  23.                     break;
  24.  
  25.                 case 'b':
  26.  
  27.                     b = 5;
  28.                     break;
  29.  
  30.               }
  31.  
  32.               
  33.               
  34.                  int[] cisla = new int[b];
  35.  
  36.               
  37.               for (int i = 0; i < cisla.length; i ++) {
  38.               
  39.                     System.out.print("Zadejte znak: ");
  40.                   cisla[i] = System.in.read();
  41.                               
  42.               }
  43.               
  44.               boolean end = false;
  45.               
  46.               
  47.               do {
  48.               
  49.                 System.out.println("Jakou operaci pozadujete?");
  50.                   System.out.println("a = scitani");
  51.                   System.out.println("b = nasobeni"); 
  52.                   System.out.println("c = vypsani jednotlivych cisel");
  53.                 System.out.println("z = ukonceni programu");
  54.  
  55.                 o = (char) System.in.read();
  56.                 
  57.                 if (o == 'a') {
  58.                    
  59.                    int soucet = 0;
  60.                    for (int i = 0; i < cisla.length; i ++) {
  61.                    
  62.                           soucet += cisla[i];
  63.                        
  64.                    }
  65.                    
  66.                    System.out.println("Soucet cisel je " + soucet);
  67.                 
  68.                 } else if (o == 'b') {
  69.                 
  70.                   int soucin = 0;
  71.                   for (int i = 0; i < cisla.length; i ++) {
  72.                   
  73.                         soucin *= cisla[i];
  74.                       
  75.                   }
  76.                   
  77.                   System.out.println("Soucin cisel je " + soucin);
  78.                 
  79.                 } else if (o == 'c') {
  80.                 
  81.                   System.out.println("Pole obsahuje nasledujici cisla:");
  82.                   for (int i = 0; i < cisla.length; i ++) {
  83.                   
  84.                         
  85.                       System.out.print(cisla[i] + ", ");
  86.                       
  87.                   }
  88.                 
  89.                 } else if (o == 'z') {
  90.                 
  91.                   end = true;
  92.                 
  93.                 }
  94.                 
  95.               } while (! end);   
  96.        }
  97. }
  98.       
  99.