Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Abbreviate{
  4. public static void main(String[] args){
  5. Scanner console = new Scanner(System.in);
  6. String word="";
  7. int n;
  8. while(!word.equals("goodbye")){
  9. System.out.print("Enter a word with 7 or more letters: ");
  10. word = console.nextLine();
  11. word = word.trim(); // get rid of leading and trailing spaces
  12. n = word.length();
  13. // you write the code here to test if the words has 7 or more letters
  14. // and either print an error message or form the abbreviation...
  15. if(n>=7){
  16. String newWord = word.substring(0,4)+(n-5)+word.substring(n-1);
  17. System.out.println("The abbreviation of "+word+" is "+newWord);
  18. } else{
  19. System.out.println("The word must have length 7 or more");
  20. }
  21.  
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement