Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class madeInPrevMonth {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         System.out.println("Insert number of orders in the current month:");
  10.         int n = Integer.parseInt(scanner.nextLine());
  11.  
  12.         List<String> emailsCurrentMonth = new ArrayList<>();
  13.  
  14.         System.out.println("Insert emails of customers:");
  15.         while(n-- > 0){
  16.             String emailCurrentMonth = scanner.nextLine();
  17.             emailsCurrentMonth.add(emailCurrentMonth);
  18.         }
  19.  
  20.         System.out.println("Insert number of orders in the prev month:");
  21.         int m = Integer.parseInt(scanner.nextLine());
  22.  
  23.         List<String> emailsPrevMonth = new ArrayList<>();
  24.  
  25.         System.out.println("Insert emails of customers:");
  26.         while(m-- > 0){
  27.             String emailPrevMonth = scanner.nextLine();
  28.             emailsPrevMonth.add(emailPrevMonth);
  29.         }
  30.        
  31.  
  32.         List<String> emailsOccur = new ArrayList<>();
  33.  
  34.         if (emailsCurrentMonth.size() >= emailsPrevMonth.size()) {
  35.             for (int i = 0; i < emailsCurrentMonth.size(); i++) {
  36.                 for (int j = 0; j < emailsPrevMonth.size(); j++) {
  37.                     if (emailsCurrentMonth.get(i).equals(emailsPrevMonth.get(j))){
  38.                         emailsOccur.add(emailsCurrentMonth.get(i));
  39.                     }
  40.                 }
  41.             }
  42.         } else {
  43.             for (int i = 0; i < emailsPrevMonth.size(); i++) {
  44.                 for (int j = 0; j < emailsCurrentMonth.size(); j++) {
  45.                     if(emailsPrevMonth.get(i).equals(emailsCurrentMonth.get(j))){
  46.                         emailsOccur.add(emailsPrevMonth.get(i));
  47.                     }
  48.                 }
  49.             }
  50.         }
  51.  
  52.         List<String> emailCounter = new ArrayList<>();
  53.  
  54.         for (int i = 0; i < emailsOccur.size(); i++) {
  55.             if(!emailCounter.contains(emailsOccur.get(i))){
  56.                 emailCounter.add(emailsOccur.get(i));
  57.             }
  58.         }
  59.  
  60.         System.out.println();
  61.         System.out.println("Users made order in this and prev month = " + emailCounter.size());
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement