GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JavaArrays/WordsLength.md at main · AlexaJavaDev/JavaArrays

Expand file tree

/

WordsLength.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
57 lines (49 loc) · 1.22 KB
/

WordsLength.md

Copy path

File metadata and controls

57 lines (49 loc) · 1.22 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Вариант 1

Что делает:
Выводит только те слова, длина которых больше 4 символов. Код:

public class WordsLength {
    public static void main(String[] args) {
        String[] str = {"Hello", "World", "Java", "Code"};
        System.out.println(filterWordsLength(str));
    }

    public static String filterWordsLength(String[] str) {
        String res = "";
        for (int i = 0; i < str.length; i++) {
            if (str[i].length() > 4) {
                res += str[i] + "\n";
            }
        }
        return res;
    }
}

Пример вывода в консоли:

Hello
World

Вариант 2

Что делает:
Выводит каждое слово из массива и его длину.

Код:

public class WordLength {
    public static void main(String[] args) {
        String[] str = {"apple", "banana", "cherry"};
        String res = "";

        for (int i = 0; i < str.length; i++) {
            res += str[i] + ": " + str[i].length() + "\n";
        }
        System.out.println(res);
    }
}

Пример вывода в консоли:

apple: 5
banana: 6
cherry: 6
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.