Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import static java.lang.System.*;
  4.  
  5. public class DonorSort
  6. {
  7. public static void main(String args[]) throws IOException
  8. {
  9. Scanner file = new Scanner(new File("sample.txt"));
  10. int num = file.nextInt();
  11. file.nextLine();
  12. String line1 = file.nextLine();
  13. String line2 = file.nextLine();
  14.  
  15. String temp = "";
  16. ArrayList<String> group1 = new ArrayList<String>();
  17. ArrayList<String> group2 = new ArrayList<String>();
  18.  
  19. ArrayList<String> lastYear = new ArrayList<String>();
  20. ArrayList<String> bothYears = new ArrayList<String>();
  21. ArrayList<String> thisYear = new ArrayList<String>();
  22.  
  23. // for(int s=0; s<
  24. for(int i=0; i<line1.length(); i++)
  25. {
  26. if(line1.charAt(i) == ',')
  27. {
  28. group1.add('"' + temp + '"');
  29. temp = "";
  30. continue;
  31. }else{
  32. temp = temp + line1.charAt(i);
  33. }
  34. }
  35. group1.add('"' + temp + '"');
  36. temp = "";
  37.  
  38. for(int x=0; x<line2.length(); x++)
  39. {
  40. if(line2.charAt(x) == ',')
  41. {
  42. group2.add('"' + temp + '"');
  43. temp = "";
  44. continue;
  45. }else{
  46. temp = temp + line2.charAt(x);
  47. }
  48. }
  49. group2.add('"' + temp + '"');
  50. temp = "";
  51.  
  52. System.out.println(group1);
  53. System.out.println(group2);
  54.  
  55. for(int i=0; i < group1.size(); i++)
  56. {
  57. for(int x=0; x < group2.size(); x++)
  58. {
  59. if(group1.get(x).equals(group2.get(x)))
  60. {
  61. String holder = group1.get(x);
  62. bothYears.add(holder);
  63. }
  64. }
  65. }
  66.  
  67. System.out.println(lastYear);
  68. System.out.println(bothYears);
  69. System.out.println(thisYear);
  70.  
  71.  
  72. }
  73.  
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement