Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Abbreviate{
- public static void main(String[] args){
- Scanner console = new Scanner(System.in);
- String word="";
- int n;
- while(!word.equals("goodbye")){
- System.out.print("Enter a word with 7 or more letters: ");
- word = console.nextLine();
- word = word.trim(); // get rid of leading and trailing spaces
- n = word.length();
- // you write the code here to test if the words has 7 or more letters
- // and either print an error message or form the abbreviation...
- if(n>=7){
- String newWord = word.substring(0,4)+(n-5)+word.substring(n-1);
- System.out.println("The abbreviation of "+word+" is "+newWord);
- } else{
- System.out.println("The word must have length 7 or more");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement