Advertisement
CR7CR7

common items

Feb 20th, 2023
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. // Online Java Compiler
  2. // Use this editor to write, compile and run your Java code online
  3. //taskOne - Arrays
  4. class HelloWorld {
  5.     // common items
  6.     public static void main(String[] args) {
  7.         //first solution
  8.         String [] arr2={"10","hey","4","hello"};
  9.         String [] arr1 ={"Hey","hello","2","4"};
  10.         int i=0;
  11.         int j=0;
  12.         for (i=0;i<arr2.length;i++){
  13.             for(j=0;j<arr1.length;j++){
  14.                 if (arr1[j]==arr2[i]){
  15.                     System.out.print(arr1[j]+" ");
  16.                 }
  17.                
  18.             }
  19.         }
  20.         System.out.println();
  21.         String [] arr3  ={"i","love","to","code"};
  22.         String [] arr4 ={"code","i","love","to"};
  23.         for(String item4:arr4){
  24.             for(String item3:arr3){
  25.                 if(item3.equals(item4)){
  26.                     System.out.print(item3+" ");
  27.                 }
  28.                
  29.             }
  30.         }
  31.         //System.out.println("Hello, World!");
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement