Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- static List<String> words1 = new ArrayList<String>();
- static List<String> words2 = new ArrayList<String>();
- static Scanner i = new Scanner(System.in);
- public static void main(String args[])
- {
- String string1, string2;
- string1 = getString(1);
- string2 = getString(2);
- AddWordsToArray(string1, string2);
- union();
- difference();
- intersection();
- System.out.println("Vowels in String 1: " + vowel(string1));
- System.out.println("Vowels in String 2: " + vowel(string2));
- }
- public static String getString(int StringNo)
- {
- String s;
- System.out.println("Enter String "+ StringNo + ": ");
- s = i.toString();
- return s;
- }
- public static void AddWordsToArray( String s1, String s2)
- {
- String str[] = s1.split(" ");
- words1 = Arrays.asList(str);
- String str2[] = s2.split(" ");
- words2 = Arrays.asList(str2);
- }
- public static void union()
- {
- List<String> union = new ArrayList<String>();
- union.addAll(words1);
- union.addAll(words2);
- String[] s1 = union.toArray(new String[0]);
- System.out.print("Union is");
- System.out.println(Arrays.toString(s1));
- quicksort.quickSortt(s1);
- System.out.println("Using Quick Sort: " +Arrays.toString(s1));
- }
- public static void difference()
- {
- List<String> diff = new ArrayList<String>();
- for(String temp: words1)
- {
- if(!words2.contains(temp))
- {
- diff.add(temp);
- }
- }
- System.out.println("The Difference of the lines is: " + diff);
- }
- public static void intersection()
- {
- List<String> inter = new ArrayList<String>();
- for(String temp: words1)
- {
- if(words2.contains(temp))
- {
- inter.add(temp);
- }
- }
- System.out.println("The Intersection of the lines is: " + inter);
- }
- public static int vowel(String a)
- {
- int count = 0;
- for(int in = 0; in < a.length(); in++)
- {
- char ch = a.charAt(in);
- if(ch == 'a'|| ch == 'e'|| ch == 'i' ||ch == 'o' ||ch == 'u')
- {
- count ++;
- }
- if(ch == 'A'|| ch == 'E'|| ch == 'I' ||ch == 'O' ||ch == 'U')
- {
- count ++;
- }
- }
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement