Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class madeInPrevMonth {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Insert number of orders in the current month:");
- int n = Integer.parseInt(scanner.nextLine());
- List<String> emailsCurrentMonth = new ArrayList<>();
- System.out.println("Insert emails of customers:");
- while(n-- > 0){
- String emailCurrentMonth = scanner.nextLine();
- emailsCurrentMonth.add(emailCurrentMonth);
- }
- System.out.println("Insert number of orders in the prev month:");
- int m = Integer.parseInt(scanner.nextLine());
- List<String> emailsPrevMonth = new ArrayList<>();
- System.out.println("Insert emails of customers:");
- while(m-- > 0){
- String emailPrevMonth = scanner.nextLine();
- emailsPrevMonth.add(emailPrevMonth);
- }
- List<String> emailsOccur = new ArrayList<>();
- if (emailsCurrentMonth.size() >= emailsPrevMonth.size()) {
- for (int i = 0; i < emailsCurrentMonth.size(); i++) {
- for (int j = 0; j < emailsPrevMonth.size(); j++) {
- if (emailsCurrentMonth.get(i).equals(emailsPrevMonth.get(j))){
- emailsOccur.add(emailsCurrentMonth.get(i));
- }
- }
- }
- } else {
- for (int i = 0; i < emailsPrevMonth.size(); i++) {
- for (int j = 0; j < emailsCurrentMonth.size(); j++) {
- if(emailsPrevMonth.get(i).equals(emailsCurrentMonth.get(j))){
- emailsOccur.add(emailsPrevMonth.get(i));
- }
- }
- }
- }
- List<String> emailCounter = new ArrayList<>();
- for (int i = 0; i < emailsOccur.size(); i++) {
- if(!emailCounter.contains(emailsOccur.get(i))){
- emailCounter.add(emailsOccur.get(i));
- }
- }
- System.out.println();
- System.out.println("Users made order in this and prev month = " + emailCounter.size());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement