// Program 68: Sentence Length and Alphabetical Word Order import java.util.*; class AlphabeticalWords { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine().trim(); if (!s.matches("[A-Z]+( [A-Z]+)*[.?!]")) { System.out.println("INVALID SENTENCE"); return; } String body = s.substring(0, s.length() - 1); String[] words = body.split(" "); Arrays.sort(words); System.out.println("LENGTH = " + words.length); System.out.println("REARRANGED SENTENCE:"); System.out.println(String.join(" ", words)); } }