I have a corpus that contains a short story with 5 "who", "what", "when", "where", "why" questions. I have used Stanford NLP API to separate the story into sentences which then the I get the lemma for each word in the sentence giving me the base word. I do the same with the questions. I have the story and the sentences saved in separate files from which I use WS4J to help me determine which sentence from the story can answer each question.
I am using this method that takes 2 Strings (question, and the possible) and compares them to each other and returns a value which its a possible answer to the question or not.
public int compSen(double prob, String sen1, String sen2) {
int cant = 0;
// String sen2c = remStopWords(sen2);
String[] sent1 = getWords(sen1);
String[] sent2 = getWords(sen2);
for (int s = 0; s < sent2.length - 1; s++) {
for (int m = s + 1; m < sent2.length; m++) {
if (sent2[s] != "" && sent2[s].equals(sent2[m])) {
sent2[m] = "";
}
}
}
for (int i = 0; i < sent1.length; i++) {
for (int j = 0; j < sent2.length; j++) {
if (sent2[j] != "") {
double res = compWord(sent1[i].trim(), sent2[j].trim());
if (res >= prob) {
// System.out.println(sent1[i] + " " + sent2[j]);
// System.out.println(res);
cant++;
}
}
}
}
return cant;
}
My other method which compares the words is like this:
public double compWord(String word1, String word2) {
ILexicalDatabase db = new NictWordNet();
WS4JConfiguration.getInstance().setMFS(true);
RelatednessCalculator rc = new Path(db);
// String word1 = "gender";
// String word2 = "sex";
List<POS[]> posPairs = rc.getPOSPairs();
double maxScore = -1D;
for (POS[] posPair : posPairs) {
List<Concept> synsets1 = (List<Concept>) db.getAllConcepts(word1, posPair[0].toString());
List<Concept> synsets2 = (List<Concept>) db.getAllConcepts(word2, posPair[1].toString());
for (Concept synset1 : synsets1) {
for (Concept synset2 : synsets2) {
Relatedness relatedness = rc.calcRelatednessOfSynset(synset1, synset2);
double score = relatedness.getScore();
if (score > maxScore) {
maxScore = score;
}
}
}
}
if (maxScore == -1D) {
maxScore = 0.0;
}
// System.out.println(word1);
// System.out.println(word2);
//
// System.out.println(maxScore);
// System.out.println("sim('" + word1 + "', '" + word2 + "') = " + maxScore);
return maxScore;
}
I was wondering if there is another way to better answer questions from a corpus given a story to analyze, since my method is very basic and I managed to answer almost 1-3 questions out of 20. To me this is really good. Any help, idea is appreciated.
You are testing for an empty string the wrong way. For example
if (sent2[j] != "") { ...
Unless the API you are using guarantees to canonicalize the strings it returns, that is unreliable. Java does not guarantee that all empty strings are the same object as "". The following are reliable ways to test if a string is empty:
if ("".equal(sent2[j])) { ... // works even for a null !!!
if (sent2[j].equals("") { ...
if (sent2[j].length() == 0) { ...
if (sent2[j].isEmpty()) { ... // Java 6 onwards
This may not be what it is causing the program to fail, but it is most likely an error.
Related
I am currently in a Intro to Computer Language class and everyone few lessons I have to develop some minimal programs (we are given 5 different prompts and have to pick three of them to complete). Due to time, I moved on and completed a different program, but I still want to understand what is going wrong with this one.
It is supposed to translate a given phrase into Pig Latin using for loops and different methods (as broken down in their template, which I cannot change, though I know there is a more efficient way). I can get the words in the phrases to translate, but when I print out the array (either by converting it to a string or running a for loop to print each element out separately) some of the elements only print the reference code. Could someone tell me what's going on? Below is the code and then a sample of a few print outs.
import java.util.Arrays;
import java.util.Scanner;
public class PigLatin {
public static void main (String[] args){
Scanner scnr = new Scanner(System.in);
String userWord;
userWord = scnr.nextLine();
userWord = userWord.toLowerCase();
String[] wordArry = userWord.split(" ");
print(wordArry);
}
public static String[] translate(String[] words){
String[] pigLatin = new String[words.length];
for (int i = 0; i < words.length; ++i) {
if (isVowel(words[i].charAt(0)) == true){
pigLatin[i] = words + "ay";
}
else if (words[i].charAt(0) == 'y') {
pigLatin[i] = words[i].substring(findFirstVowel(words[i]), words[i].length()) + words[i].substring(0, findFirstVowel(words[i])) + "ay";
}
else {
pigLatin[i] = words[i].substring(findFirstVowel(words[i]), words[i].length()) + words[i].substring(0, findFirstVowel(words[i])) + "ay";
}
}
return pigLatin;
}
public static int findFirstVowel(String s){
char[] vowList = {'a','e','i','o','u','y'};
for (int i = 1; i < s.length(); ++i) {
for (int j = 0; j < vowList.length; ++j) {
if (s.charAt(i) == vowList[j]) {
return i;
}
}
}
return -1;
}
public static boolean isVowel(char c){
boolean vowel = false;
char[] vowList = {'a','e','i','o','u'};
for (int i = 0; i < vowList.length; ++i) {
if (c == vowList[i]) {
vowel = true;
}
}
return vowel;
}
public static void print(String[] words){
String[] newArry = new String[words.length];
for (int i = 0; i < words.length; ++i) {
newArry[i] = words[i];
}
String finalPrint = Arrays.toString(translate(newArry));
finalPrint = finalPrint.replace("[", "");
finalPrint = finalPrint.replace(",", "");
finalPrint = finalPrint.replace("]", "");
System.out.println(finalPrint);
}
}
Here are some of the printed responses:
Input: the rain in spain stays mainly in the plain
Output: ethay ainray [Ljava.lang.String;#17c68925ay ainspay aysstay ainlymay [Ljava.lang.String;#17c68925ay ethay ainplay
Expected: ethay ainray inay ainspay aysstay ainlymay inay ethay ainplay
Input: you should have stayed with the soup question
OutPut: ouyay ouldshay avehay ayedstay ithway ethay oupsay uestionqay
This print's out correctly
Input: the stuff that dreams are made of
Output: ethay uffstay atthay eamsdray [Ljava.lang.String;#17c68925ay ademay [Ljava.lang.String;#17c68925ay
Expected: ethay uffstay atthay eamsdray areay ademay ofay
I cannot find an answer as to why this is happening. Please let me know if you need any additional information. Thanks!
You have a mistake (typo, likely) in this block:
if (isVowel(words[i].charAt(0)) == true){
pigLatin[i] = words + "ay";
}
It should be instead (note you don't need to compare boolean value with true):
if (isVowel(words[i].charAt(0))) {
pigLatin[i] = words[i] + "ay";
}
Also, you don't need to copy your array in print() method - translate() doesn't modify input array in any way.
Finally, instead of replacing the output of Arrays.toString, you could use String.join, so your print method would look like:
public static void print(String[] words){
System.out.println(String.join(" ", translate(words)));
}
pigLatin[i] = words + "ay";
This line. You are appending string to an array. Change it to:
pigLatin[i] = words[i] + "ay";
Side note 1:
for (int i = 0; i < words.length; ++i) {
newArry[i] = words[i];
}
This loop can be changed to:
System.arraycopy(words, 0, newArry, 0, words.length);
Side note 2:
Splitting on "\\s+" is better. It also takes care of multiple spaces.
Side note 3:
if (isVowel(words[i].charAt(0)) == true) {
This can be simplified as:
if (isVowel(words[i].charAt(0))) {
Side note 4:
for (char value : vowList) {
if (c == value) {
vowel = true;
break;
}
}
Using break for slightly better performance. Also, using foreach loop.
Final side note:
finalPrint = finalPrint.replace("[", "")
.replace(",", "")
.replace("]", "");
Chaining of replace calls.
I will ask this again. I have this problem which is to create a program that would read a string input from the user (sentence or word). And the Nth number (from the user) will turn into upper case and the rest will be in lowercase.
Example:
string = "good morning everyone"
n = 2
Output = gOod mOrning eVeryone
for (int x = 0; x < s.length(); x++)
if (x == n-1){
temp+=(""+s.charAt(x)).toUpperCase();
}else{
temp+=(""+s.charAt(x)).toLowerCase();
}
s=temp;
System.out.println(s);
}
Output: gOod morning everyone
I know what you want to happen - but you didn't phrase your question very well. The only part your missing is iterating through every word in the sentence. If you asked "how do I apply a function on every word in a String" you likely would have gotten a better response.
This is a bit sloppy since it adds a trailing " " to the end - but you could fix that easily.
public class Test {
static String test = "This is a test.";
public static void main(String[] args) {
String[] words = test.split(" ");
String result = "";
for (String word : words) {
result += nthToUpperCase(word, 2);
result += " ";
}
System.out.println(result);
}
public static String NthToUpperCase(String s, int n) {
String temp = "";
for (int i = 0; i < s.length(); i++) {
if (i == (n-1)) {
temp+=Character.toString(s.charAt(i)).toUpperCase();
} else {
temp+=Character.toString(s.charAt(i));
}
}
return temp;
}
}
You can do this with two for loops. Iterate over each word and within the iteration iterate over each character.
toUpperCase(2, "good morning everyone");
private static void toUpperCase(int nth, String sentence) {
StringBuilder result = new StringBuilder();
for(String word : sentence.split(" ")) {
for(int i = 0; i < word.length(); i++) {
if(i > 0 && i % nth - 1 == 0) {
result.append(Character.toString(word.charAt(i)).toUpperCase());
} else {
result.append(word.charAt(i));
}
}
result.append(" ");
}
System.out.println(result);
}
gOoD mOrNiNg eVeRyOnE
I am trying to write a program that will allows users to make short blog entries by typing abbreviations for common words. On completion of the input, Program will expand the abbreviations according to the lexicon defined.
Conditions
A substituted word must be the shortest word that can be formed by adding zero or more letters (or punctuation symbols) to the abbreviation.
If two or more unique words can be formed by adding the same number of letters, then the abbreviation should be printed as it is.
Input
The input is divided into two sections.
The first section is the lexicon itself, and the second section is a user's blog entry that needs to be expanded. The sections are divided by a single | character.
For example:-
cream chocolate every ever does do ice is fried friend friends lick like floor favor flavor flower best but probably poorly say says that what white our you your strawberry storyboard the | wht flvr ic crm ds yr bst fnd lke? ur frds lk stbry, bt choc s prly th bs flr vr!
Output
what flavor ice cream does your best friend like? our friends lk strawberry, but chocolate is poorly the best floor ever!
I have written the program for this and tested it locally with many different test cases with success but it fails on submission to test server.
An automated Test suit runs to validate the program’s output on its submission to test server. In case of failure, details of the failing test case/cases are not visible.
Below is the program
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BlogEntry {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[][] info = readInput();
String[] output = inputExpander(info[0],info[1]);
//System.out.println();
for(int i = 0; i < output.length; ++i) {
if(i!=0)
System.out.print(" ");
System.out.print(output[i]);
}
}
public static String[][] readInput() {
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(
System.in));
String input = null;
String[][] info = new String[2][];
String[] text;
String[] abbr;
try {
input = bufferReader.readLine();
StringTokenizer st1 = new StringTokenizer(input, "|");
String first = "", second = "";
int count = 0;
while (st1.hasMoreTokens()) {
++count;
if(count == 1)
first = st1.nextToken();
if(count == 2)
second = st1.nextToken();
}
st1 = new StringTokenizer(first, " ");
count = st1.countTokens();
text = new String[count];
count = 0;
while (st1.hasMoreTokens()) {
text[count] = st1.nextToken();
count++;
}
st1 = new StringTokenizer(second, " ");
count = st1.countTokens();
abbr = new String[count];
count = 0;
while (st1.hasMoreTokens()) {
abbr[count] = st1.nextToken();
count++;
}
info[0] = text;
info[1] = abbr;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return info;
}
public static String[] inputExpander(String[] text, String[] abbr) {
String[] output = new String[abbr.length];
boolean result;
for (int i = 0; i < abbr.length; ++i) {
String abbrToken = abbr[i];
char[] char_abbr_token = abbrToken.toCharArray();
for (int j = 0; j < text.length; ++j) {
String textToken = text[j];
boolean flag2 = false;
if ((char_abbr_token[char_abbr_token.length - 1] == '!')
|| (char_abbr_token[char_abbr_token.length - 1] == '?')
|| (char_abbr_token[char_abbr_token.length - 1] == ',')
|| (char_abbr_token[char_abbr_token.length - 1] == ';')) {
flag2 = true;
}
char[] char_text_token = textToken.toCharArray();
result = ifcontains(char_text_token, char_abbr_token);
if (result) {
int currentCount = textToken.length();
int alreadyStoredCount = 0;
if (flag2)
textToken = textToken
+ char_abbr_token[char_abbr_token.length - 1];
if (output[i] == null)
output[i] = textToken;
else {
alreadyStoredCount = output[i].length();
char[] char_stored_token = output[i].toCharArray();
if ((char_stored_token[char_stored_token.length - 1] == '!')
|| (char_stored_token[char_stored_token.length - 1] == '?')
|| (char_stored_token[char_stored_token.length - 1] == ',')
|| (char_stored_token[char_stored_token.length - 1] == ';')) {
alreadyStoredCount -= 1;
}
if (alreadyStoredCount > currentCount) {
output[i] = textToken;
} else if (alreadyStoredCount == currentCount) {
output[i] = abbrToken;
}
}
}
}
if(output[i] == null)
output[i] = abbrToken;
}
return output;
}
public static boolean ifcontains(char[] char_text_token,
char[] char_abbr_token) {
int j = 0;
boolean flag = false;
for (int i = 0; i < char_abbr_token.length; ++i) {
flag = false;
for (; j < char_text_token.length; ++j) {
if ((char_abbr_token[i] == '!') || (char_abbr_token[i] == '?')
|| (char_abbr_token[i] == ',')
|| (char_abbr_token[i] == ';')) {
flag = true;
break;
}
if (char_abbr_token[i] == char_text_token[j]) {
flag = true;
break;
}
}
if (!flag)
return flag;
}
//System.out.println("match found" + flag);
return flag;
}
}
Can someone direct/hint me to/about the possible use case which I may have missed in the implementation? Thanks in advance.
Ran your program with duplicate word in input (lexicon). When a word is repeated in the lexicon, it is not getting expanded because the check is only on the length(line no. 112) of the stored word not its content.
I think you need to check:-
If same word appears more than once then expand.
If 2 or more unique words of same length appear then keep it short.
How would I approach solving this:
Parse the input, tokenize the lexicon and the text.
For each (possibly abbreviated) token like choc convert it to a regular expression like .*c.*h.*o.*c.*.
Search for shortest lexicon words matching this regular expression. Replace the text token if exactly one is found, otherwise leave it alone.
It is quite hard to say what's wrong with your code without careful debugging. It is hard to understand what one or the other part of the code does, it's not quite self-evident.
I have csv file with 200k rows and 3 types of MAC address defined as:
ECE1A9312000
E8:6D:52:75:2D:16
24-C9-A1-15-89-B0
My goal to stay only with colon-separated form.
So to convert - to : is not big deal:
mac = mac.replace("-", ":");
But how to convert ECE1A9312000 to EC:E1:A9:31:20:00.
I thought to use regex but its too expensive to use groups for so many data (~80k).
Do I need to run over each char and append :
like:
for(int i=0; i<mac.length(); i++){
ch = mac.charAt(i);
if(i % 2 == 0 && i != 0){
tmp += ':';
}
tmp += ch;
}
or there is more efficient way?
Thank you,
I threw together a totally unoptimized program based on your discarded regex approach and timed it. It completed in 650 ms (250 ms with warmup). The slowest part doesn't involve the regex, but String.format. If we replace it with a straight StringBuilder approach, the time drops to 40 ms.
public class Test {
static Pattern regex = Pattern.compile("(..)(..)(..)(..)(..)(..)");
public static void main(String[] args) {
final List<String> inMacs = new ArrayList<>(), outMacs = new ArrayList<>();
for (int i = 0; i < 80_000; i++) inMacs.add(mac());
final long start = System.nanoTime();
for (String mac : inMacs) {
final Matcher m = regex.matcher(mac);
m.matches();
outMacs.add(String.format("%s:%s:%s:%s:%s:%s",
m.group(1), m.group(2), m.group(3), m.group(4), m.group(5), m.group(6)));
}
System.out.println("Took " + (System.nanoTime() - start)/1_000_000 + " milliseconds");
final Iterator<String> it = outMacs.iterator();
for (int i = 0; i < 100; i++) System.out.println(it.next());
}
static Random rnd = new Random();
static String mac() {
final long mac = (long) (rnd.nextDouble()*(1L<<48));
return String.format("%012x", mac).toUpperCase();
}
}
If you are really looking for a fast solution, then avoid the regex and use a simple test to detect your MAC format:
static List<String> fixMacs(List<String> inMacs) {
final List<String> outMacs = new ArrayList<>(inMacs.size());
for (String mac : inMacs) outMacs.add(
mac.charAt(2) == '-'? mac.replace("-", ":")
: mac.charAt(2) != ':'? fixMac(mac)
: mac);
return outMacs;
}
static String fixMac(String inMac) {
final StringBuilder b = new StringBuilder(18);
for (int i = 0; i < inMac.length(); i++) {
b.append(inMac.charAt(i));
if (i%2 == 1 && i != inMac.length()-1) b.append(':');
}
return b.toString();
}
With this approach I measured just 8 ms for your 80,000 MACs.
Iterate through it character by character, every two steps if the character found is '-' replace it with ':', if it's a letter or a number then insert a ':' character.
try this
String x="ECE1A9312000";
String finals="";
for(int i=0;i<x.length();i=i+2)
{
if((i+2)<x.length())
finals+=x.substring(i, i+2)+":";
if((i+2)==x.length())
{
finals+=x.substring(i, i+2);
}
}
System.out.println(finals);
output
EC:E1:A9:31:20:00
Split every 2 chars with regexp and join with delimiter using String.join:
public static String convertToColonSeparatedMac(String mac) {
if (mac.contains(":"))
return mac;
if (mac.contains("-"))
return mac.replaceAll("-", ":");
return String.join(":", mac.split("(?<=\\G.{2})"));
}
And you may validate it before converting:
private static final Pattern MAC_PATTERN = Pattern.compile("(^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$)|([0-9A-Fa-f]{12})");
public static boolean isValidMac(String mac) {
return MAC_PATTERN.matcher(mac).matches();
}
String mac[] = {"ECE1A9312000", "24-C9-A1-15-89-B0", "E8:6D:52:75:2D:16"};
for (int i = 0; i< mac.length; i++)
{
if (mac[i].charAt(2) == '-')
mac[i] = mac[i].replace("-", ":");
else if (mac[i].charAt(2) != ':')
mac[i] = new StringBuilder(mac[i].substring(0,2)).append(":").append(mac[i].substring(2,4))
.append(":").append(mac[i].substring(4,6)).append(":").append(mac[i].substring(6,8))
.append(":").append(mac[i].substring(8,10)).append(":").append(mac[i].substring(10)).toString();
}
for (int i = 0; i< mac.length; i++)
System.out.println(mac[i]);
OUTPUT:
EC:E1:A9:31:20:00
24:C9:A1:15:89:B0
E8:6D:52:75:2D:16
My goal is to write a program that compresses a string, for example:
input: hellooopppppp!
output:he2l3o6p!
Here is the code I have so far, but there are errors.
When I have the input: hellooo
my code outputs: hel2l3o
instead of: he213o
the 2 is being printed in the wrong spot, but I cannot figure out how to fix this.
Also, with an input of: hello
my code outputs: hel2l
instead of: he2lo
It skips the last letter in this case all together, and the 2 is also in the wrong place, an error from my first example.
Any help is much appreciated. Thanks so much!
public class compressionTime
{
public static void main(String [] args)
{
System.out.println ("Enter a string");
//read in user input
String userString = IO.readString();
//store length of string
int length = userString.length();
System.out.println(length);
int count;
String result = "";
for (int i=1; i<=length; i++)
{
char a = userString.charAt(i-1);
count = 1;
if (i-2 >= 0)
{
while (i<=length && userString.charAt(i-1) == userString.charAt(i-2))
{
count++;
i++;
}
System.out.print(count);
}
if (count==1)
result = result.concat(Character.toString(a));
else
result = result.concat(Integer.toString(count).concat(Character.toString(a)));
}
IO.outputStringAnswer(result);
}
}
I would
count from 0 as that is how indexes work in Java. Your code will be simpler.
would compare the current char to the next one. This will avoid printing the first character.
wouldn't compress ll as 2l as it is no smaller. Only sequences of at least 3 will help.
try to detect if a number 3 to 9 has been used and at least print an error.
use the debugger to step through the code to understand what it is doing and why it doesn't do what you think it should.
I am doing it this way. Very simple:
public static void compressString (String string) {
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < string.length(); i++) {
int count = 1;
while (i + 1 < string.length()
&& string.charAt(i) == string.charAt(i + 1)) {
count++;
i++;
}
if (count > 1) {
stringBuffer.append(count);
}
stringBuffer.append(string.charAt(i));
}
System.out.println("Compressed string: " + stringBuffer);
}
You can accomplish this using a nested for loops and do something simial to:
count = 0;
String results = "";
for(int i=0;i<userString.length();){
char begin = userString.charAt(i);
//System.out.println("begin is: "+begin);
for(int j=i+1; j<userString.length();j++){
char next = userString.charAt(j);
//System.out.println("next is: "+next);
if(begin == next){
count++;
}
else{
System.out.println("Breaking");
break;
}
}
i+= count+1;
if(count>0){
String add = begin + "";
int tempcount = count +1;
results+= tempcount + add;
}
else{
results+= begin;
}
count=0;
}
System.out.println(results);
I tested this output with Hello and the result was He2lo
also tested with hellooopppppp result he2l3o6p
If you don't understand how this works, you should learn regular expressions.
public String rleEncodeString(String in) {
StringBuilder out = new StringBuilder();
Pattern p = Pattern.compile("((\\w)\\2*)");
Matcher m = p.matcher(in);
while(m.find()) {
if(m.group(1).length() > 1) {
out.append(m.group(1).length());
}
out.append(m.group(2));
}
return out.toString();
}
Try something like this:
public static void main(String[] args) {
System.out.println("Enter a string:");
Scanner IO = new Scanner(System.in);
// read in user input
String userString = IO.nextLine() + "-";
int length = userString.length();
int count = 0;
String result = "";
char new_char;
for (int i = 0; i < length; i++) {
new_char = userString.charAt(i);
count++;
if (new_char != userString.charAt(i + 1)) {
if (count != 1) {
result = result.concat(Integer.toString(count + 1));
}
result = result.concat(Character.toString(new_char));
count = 0;
}
if (userString.charAt(i + 1) == '-')
break;
}
System.out.println(result);
}
The problem is that your code checks if the previous letter, not the next, is the same as the current.
Your for loops basically goes through each letter in the string, and if it is the same as the previous letter, it figures out how many of that letter there is and puts that number into the result string. However, for a word like "hello", it will check 'e' and 'l' (and notice that they are preceded by 'h' and 'e', receptively) and think that there is no repeat. It will then get to the next 'l', and then see that it is the same as the previous letter. It will put '2' in the result, but too late, resulting in "hel2l" instead of "he2lo".
To clean up and fix your code, I recommend the following to replace your for loop:
int count = 1;
String result = "";
for(int i=0;i<length;i++) {
if(i < userString.length()-1 && userString.charAt(i) == userString.charAt(i+1))
count++;
else {
if(count == 1)
result += userString.charAt(i);
else {
result = result + count + userString.charAt(i);
count = 1;
}
}
}
Comment if you need me to explain some of the changes. Some are necessary, others optional.
Here is the solution for the problem with better time complexity:
public static void compressString (String string) {
LinkedHashSet<String> charMap = new LinkedHashSet<String>();
HashMap<String, Integer> countMap = new HashMap<String, Integer>();
int count;
String key;
for (int i = 0; i < string.length(); i++) {
key = new String(string.charAt(i) + "");
charMap.add(key);
if(countMap.containsKey(key)) {
count = countMap.get(key);
countMap.put(key, count + 1);
}
else {
countMap.put(key, 1);
}
}
Iterator<String> iterator = charMap.iterator();
String resultStr = "";
while (iterator.hasNext()) {
key = iterator.next();
count = countMap.get(key);
if(count > 1) {
resultStr = resultStr + count + key;
}
else{
resultStr = resultStr + key;
}
}
System.out.println(resultStr);
}