shivamisone

odeveposuition

Jul 28th, 2023
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | Source Code | 0 0
  1. import java.util.*;
  2. public class positon{
  3.     public static void main(String[] args){
  4.         Scanner sc = new Scanner(System.in);
  5.         System.out.println("enter size of arrays");
  6.         int s = sc.nextInt();
  7.         int[] ar = new int[s];
  8.         int[] ar1 = new int[s];
  9.         System.out.println("enter terms of array 1");
  10.         for(int i =0; i<s;i++){
  11.             ar[i] = sc.nextInt();
  12.         }
  13.         System.out.println("enter terms of array 2");
  14.         for(int i =0; i<s;i++){
  15.             ar1[i] = sc.nextInt();
  16.         }
  17.         int ss =0;
  18.         //2 7 5 , 3 5 2
  19.         int[] a = new int[s*2];
  20.         for(int i =0;i<s;i++){
  21.             if(ss%2!=0){
  22.             if(ar[i]%2!=0){
  23.                 a[ss] = ar[i];
  24.                 ss++;
  25.                 }
  26.             if(ar1[i]%2!=0){
  27.                
  28.                 a[ss] = ar1[i];
  29.                 ss++;
  30.             }
  31.         } else{
  32.             ss++;
  33.             i--;
  34.         }
  35.         }
  36.         ss = 0;
  37.         for(int i =0;i<s;i++){
  38.             if(ss%2 ==0){
  39.             if(ar[i]%2==0){
  40.                 a[ss] = ar[i];
  41.                 ss++;
  42.                 }
  43.             if(ar1[i]%2==0){
  44.                
  45.                 a[ss] = ar1[i];
  46.                 ss++;
  47.             }
  48.         } else {
  49.             ss++;
  50.             i--;
  51.         }
  52.     }
  53.         System.out.println(Arrays.toString(a));
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment