Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2022
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class WordorNumber2 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8. double result = 0;
  9. String allWords = "";
  10. int countWords = 0;
  11.  
  12. for (int i = 1; i <= n; i++) {
  13. String input = scanner.nextLine();
  14. char sigh = input.charAt(0);
  15. if ((sigh >= 'a' && sigh <= 'z') || (sigh >= 'A' && sigh <= 'Z')) {
  16. allWords = allWords + input + "-";
  17. countWords++;
  18. }
  19. if (sigh >= '0' && sigh <= '9') {
  20. int number;
  21. number = Integer.parseInt(input);
  22. result = result + number;
  23. }
  24. }
  25. if (countWords > 0) {
  26. System.out.println(allWords.substring(0, allWords.length() - 1));
  27. System.out.printf("%.0f", result);
  28. } else {
  29. System.out.println("no words");
  30. System.out.printf("%.0f", result);
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement