import java.util.*; public class String_length { void LengthCount(String str) { int len = str.length(); int count = 0; int i; // Print the first character System.out.print(str.charAt(0)); // Loop through characters in the string (excluding first and last) for (i = 1; i < len - 1; i++) { count++; } // Print the count of characters between first and last System.out.print(count); // Print the last character if (len > 1) { // Check if string has more than 1 character System.out.print(str.charAt(len - 1)); } } public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println("Enter the string: "); String st = s.nextLine(); String_length obj = new String_length(); obj.LengthCount(st); } }