fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. System.out.print("Введіть рядок S (до 70 символів): ");
  7. String sInput = scanner.nextLine();
  8.  
  9. if (sInput.length() > 70) {
  10. sInput = sInput.substring(0, 70);
  11. }
  12.  
  13. String[] words = sInput.split(" ");
  14. StringBuilder s3 = new StringBuilder();
  15.  
  16. for (String word : words) {
  17. if (word.length() > 0 && word.length() % 3 == 0) {
  18. s3.append(word).append(" ");
  19. }
  20. }
  21.  
  22. System.out.println("\n--- Результати ---");
  23. System.out.println("Початковий рядок S: " + sInput);
  24. System.out.println("Рядок S3 (слова, кратні 3): " + s3.toString().trim());
  25.  
  26. scanner.close();
  27. }
  28. }
Success #stdin #stdout 0.13s 60720KB
stdin
Стівен Кінг пише крутий трилер
stdout
Введіть рядок S (до 70 символів): 
--- Результати ---
Початковий рядок S: Стівен Кінг пише крутий трилер
Рядок S3 (слова, кратні 3): Стівен крутий трилер