Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8.  
  9. static List<String> words1 = new ArrayList<String>();
  10. static List<String> words2 = new ArrayList<String>();
  11. static Scanner i = new Scanner(System.in);
  12.  
  13. public static void main(String args[])
  14. {
  15. String string1, string2;
  16. string1 = getString(1);
  17. string2 = getString(2);
  18.  
  19. AddWordsToArray(string1, string2);
  20.  
  21. union();
  22. difference();
  23. intersection();
  24.  
  25. System.out.println("Vowels in String 1: " + vowel(string1));
  26. System.out.println("Vowels in String 2: " + vowel(string2));
  27.  
  28. }
  29.  
  30. public static String getString(int StringNo)
  31. {
  32. String s;
  33. System.out.println("Enter String "+ StringNo + ": ");
  34. s = i.toString();
  35. return s;
  36. }
  37.  
  38. public static void AddWordsToArray( String s1, String s2)
  39. {
  40. String str[] = s1.split(" ");
  41. words1 = Arrays.asList(str);
  42.  
  43. String str2[] = s2.split(" ");
  44. words2 = Arrays.asList(str2);
  45. }
  46.  
  47. public static void union()
  48. {
  49. List<String> union = new ArrayList<String>();
  50. union.addAll(words1);
  51. union.addAll(words2);
  52.  
  53.  
  54.  
  55. String[] s1 = union.toArray(new String[0]);
  56.  
  57.  
  58.  
  59. System.out.print("Union is");
  60. System.out.println(Arrays.toString(s1));
  61.  
  62.  
  63. quicksort.quickSortt(s1);
  64. System.out.println("Using Quick Sort: " +Arrays.toString(s1));
  65.  
  66.  
  67.  
  68.  
  69. }
  70.  
  71. public static void difference()
  72. {
  73. List<String> diff = new ArrayList<String>();
  74. for(String temp: words1)
  75. {
  76. if(!words2.contains(temp))
  77. {
  78. diff.add(temp);
  79. }
  80. }
  81.  
  82.  
  83. System.out.println("The Difference of the lines is: " + diff);
  84. }
  85.  
  86. public static void intersection()
  87. {
  88. List<String> inter = new ArrayList<String>();
  89. for(String temp: words1)
  90. {
  91. if(words2.contains(temp))
  92. {
  93. inter.add(temp);
  94. }
  95. }
  96. System.out.println("The Intersection of the lines is: " + inter);
  97. }
  98.  
  99. public static int vowel(String a)
  100. {
  101. int count = 0;
  102. for(int in = 0; in < a.length(); in++)
  103. {
  104. char ch = a.charAt(in);
  105. if(ch == 'a'|| ch == 'e'|| ch == 'i' ||ch == 'o' ||ch == 'u')
  106. {
  107. count ++;
  108. }
  109. if(ch == 'A'|| ch == 'E'|| ch == 'I' ||ch == 'O' ||ch == 'U')
  110. {
  111. count ++;
  112. }
  113. }
  114. return count;
  115. }
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement