• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jun 17th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. package Labs;
2. import java.util.Scanner;
3. import java.util.Arrays;
4. //9.2. ΠΠ°Π½Ρ Π΄Π²Π° ΠΎΠ΄Π½ΠΎΠΌΠ΅ΡΠ½ΡΡ ΠΌΠ°ΡΡΠΈΠ²Π° Xn ΠΈ Yk.
5. // Π‘ΡΠΎΡΠΌΠΈΡΠΎΠ²Π°ΡΡ Π½ΠΎΠ²ΡΠΈΜ ΠΌΠ°ΡΡΠΈΠ² Zm, ΡΠΎΡΡΠΎΡΡΠΈΠΈΜ ΠΈΠ· ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² ΠΌΠ°ΡΡΠΈΠ²Π° Xn Ρ ΡΠ΅ΡΠ½ΡΠΌΠΈ Π½ΠΎΠΌΠ΅ΡΠ°ΠΌΠΈ.
6. // ΠΠΎΠΏΠΈΡΠ°ΡΡ Π² ΠΊΠΎΠ½Π΅Ρ ΠΌΠ°ΡΡΠΈΠ²Π° ΡΡΠΌΠΌΡ ΠΎΡΡΠΈΡΠ°ΡΠ΅Π»ΡΠ½ΡΡ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² ΠΌΠ°ΡΡΠΈΠ²Π° Yk.
7. public class Ol9_2 {
8.     static double[] z = new double[0];
9.     static int k=0;
10.     public static double[] InputArray(){
11.         Scanner s = new Scanner(System.in);
12.         System.out.print("n = ");
13.         int n = s.nextInt();
14.         double[] x = new double[n];
15.         for (int i = 0; i < n; i++) {
16.             System.out.print("β" + i + ": ");
17.             x[i] = s.nextDouble();
18.         }
19.         return x;
20.     }
21.     static void FormArray(double[] x, double[] y){
22.         for(int i=0;i<x.length;i+=2){
23.                 z = Arrays.copyOf(z, z.length + 1);
24.                 z[k] = x[i];
25.                 k++;
26.             }
27.         int sum=0;
28.         for(int i=0;i<y.length;i++) {
29.             if (y[i] < 0)
30.                 sum += y[i];
31.         }
32.         k++;
33.         z = Arrays.copyOf(z, z.length + 1);
34.         z[k-1]=sum;
35.     }
36.     static void OutputArray(){
37.         for (int i = 0; i < z.length; i++)
38.             if(z[i]!=0)
39.                 System.out.printf("z(%d) = %1.2f\n", i, z[i]);
40.     }
41.     public static void main(String[] args){
42.         FormArray(InputArray(),InputArray());
43.         OutputArray();
44.     }
45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top