5 /** Pisemka - program "Analyze"
6 * Copylefted by: Harvie 2oo9 ( http://blog.harvie.cz/ )
7 * @author Thomas Harvie Mudrunka (mudruto1)
11 Zadavej posloupnost ukoncenou zapornym cislem:
18 Byla zadana nasledujici rada:
19 1.0; 2.0; 3.0; 4.0; 5.0;
29 private double[] seq = new double[101];
30 private Scanner sc = new Scanner(System.in);
32 public boolean readSeq() {
33 System.out.println("Zadavej posloupnost ukoncenou zapornym cislem:");
35 for(i=0;i<seq.length;i++) {
37 seq[i] = sc.nextDouble();
38 } catch(Exception e) {
43 System.out.println("Byla zadana nasledujici rada:");
44 for(i=0;i<seq.length;i++) {
46 System.out.print(seq[i]+"; ");
48 System.out.println("");
52 public void vypisMinimax() {
53 double min = seq[0], max = seq[0];
55 for(i=1;i<seq.length;i++) {
57 if(seq[i] < min) min = seq[i];
58 if(seq[i] > max) max = seq[i];
60 System.out.println("minimum = "+min);
61 System.out.println("maximum = "+max);
64 public void vypisDelitelne(double a) {
65 System.out.println("Cisla delitelna "+a+":");
67 for(i=0;i<seq.length;i++) {
69 if((seq[i] % a) == 0) System.out.print(seq[i]+"; ");
71 System.out.println("");
74 public boolean jePrvocislo(double a) {
75 if(a <= 1) return false;
76 if(a == 2) return true;
77 if(a % 2 == 0) return false;
79 for(i = 3; i <= Math.sqrt(a); i += 2){
80 if(a % i == 0) return false;
85 public void vypisPrvocisla() {
86 System.out.println("Prvocisla:");
88 for(i=0;i<seq.length;i++) {
90 if(jePrvocislo(seq[i])) System.out.print(seq[i]+"; ");
92 System.out.println("");
95 public void vypisPrumer() {
98 for(max=0;max<seq.length;max++) if(seq[max] < 0) break;
99 for(i=0;i<max;i++) avg += (seq[i]/max);
100 System.out.printf("prumer = %.2f\n",avg);
104 public class Analyze {
105 public static void main(String[] argv) {
106 //System.out.println("\n");
107 analyzator a = new analyzator();
109 System.err.println("Neco je spatne.");