Created
November 20, 2014 02:11
-
-
Save giladoved/cc2aedbf99ce674d3e8c to your computer and use it in GitHub Desktop.
WayTooLongWords71A
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class WayTooLongWords71A { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
int count = Integer.parseInt(in.nextLine()); //number of words in the list | |
//for each word in the list, output the result of the method abbreviation | |
for (int i = 0; i < count; i++) { | |
System.out.println(getAbbreviation(in.nextLine())); | |
} | |
} | |
//calculate and return the abbreviation based on the rules | |
private static String getAbbreviation(String word) { | |
if (word.length() <= 10) //if the word is not strictly greater than 10, there is no abbreviation, it is the whole word so return the word. | |
return word; | |
//the result is the first character plus length of the word minus the first and last letter (which is 2) plus the last letter | |
return Character.toString(word.charAt(0)).toString() + (word.length() - 2) + word.charAt(word.length() - 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment