Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class RohittDataSubScribeToOurMemePage
- {
- public static ArrayList<String> numbers = new ArrayList<String>();
- public static char[] phrase;
- public static char[] letters = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
- //Converts character to number String
- public static String charToNum(char x)
- {
- for(int i = 0;i < letters.length;i++)
- {
- if(x == letters[i])
- return Integer.toString(i);
- }
- return "error";
- }
- //Adds an element to list if requirements are met
- public static void addToList(String x)
- {
- //Makes sure there's a previous element
- int previousElement = numbers.size() - 1;
- //If there's a previous element
- if(previousElement >= 0)
- {
- //If previous element isn't a pair
- if(numbers.get(previousElement).length() == 1)
- {
- //If current String is a single letter
- if(x.length() == 1)
- numbers.set(previousElement,numbers.get(previousElement) + x);
- //If current String is a pair
- else
- {
- String first = x.substring(0,1);
- String second = x.substring(1);
- numbers.set(previousElement,numbers.get(previousElement) + first);
- numbers.add(second);
- }
- }
- //If previous element is a pair
- else
- numbers.add(x);
- }
- else
- {
- numbers.add(x);
- }
- }
- public static void main(String[] args) {
- //Takes phrase and converts to char array
- Scanner input = new Scanner(System.in);
- System.out.print("Input your phrase: ");
- String temp = input.nextLine().toLowerCase();
- phrase = new char[temp.length()];
- for(int x = 0;x < temp.length();x++)
- {
- phrase[x] = temp.charAt(x);
- }
- //Converts character to number array
- for(char element : phrase)
- {
- addToList(charToNum(element));
- }
- //Prints out the number pairs
- for(String element : numbers)
- {
- if(element.length() == 2)
- System.out.println(element);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement