Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.SQLOutput;
- import java.util.ArrayList;
- public class Main {
- public static void main(String[] args) {
- int n=5;
- int m=4;
- int numS=0;
- int numM=0;
- int [] x1=new int[n];
- //ArrayList<Integer> x1 = new ArrayList<>(5);
- for (int i=0;i<n;i++)
- x1[i] = i;
- int [] x2=new int[m];
- for (int i=0;i<m;i++)
- x2[i]=i;
- int[] y=new int[n+m-1];
- int i=0;
- for (i=0;i<m;i++) {
- int z = 0;
- for (int a = 0; a < i+1; a++) {
- z += x1[a] * x2[i-a];
- numM++;
- if (a!=0)
- numS++;
- }
- y[i] = z;
- }
- int j=1;
- for (j=1;j<n-m+1;j++){
- int z = 0;
- int b = m-1;
- for (int a = j; a < m+j; a++) {
- z += x1[a] * x2[b];
- numM++;
- if (a!=j)
- numS++;
- b--;
- }
- y[i+j-1]=z;
- }
- i=i+j-1;
- for (j=n-m+1;j<n;j++){
- int z = 0;
- int b = m-1;
- for (int a = j; a < n; a++) {
- z += x1[a] * x2[b];
- numM++;
- if (a!=j)
- numS++;
- b--;
- }
- y[i]=z;
- i++;
- }
- System.out.print("1 sequence: ");
- for (i=0;i<n;i++){
- System.out.print(x1[i]+" ");
- }
- System.out.print("\n2 sequence: ");
- for (i=0;i<m;i++){
- System.out.print(x2[i]+" ");
- }
- System.out.print("\n amount of sums: "+numS);
- System.out.print("\n amount of mult: "+numM+"\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement