Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class WordorNumber2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- double result = 0;
- String allWords = "";
- int countWords = 0;
- for (int i = 1; i <= n; i++) {
- String input = scanner.nextLine();
- char sigh = input.charAt(0);
- if ((sigh >= 'a' && sigh <= 'z') || (sigh >= 'A' && sigh <= 'Z')) {
- allWords = allWords + input + "-";
- countWords++;
- }
- if (sigh >= '0' && sigh <= '9') {
- int number;
- number = Integer.parseInt(input);
- result = result + number;
- }
- }
- if (countWords > 0) {
- System.out.println(allWords.substring(0, allWords.length() - 1));
- System.out.printf("%.0f", result);
- } else {
- System.out.println("no words");
- System.out.printf("%.0f", result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement