Skip to content

yasenltd/string-character-frequency

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

StringCharacterFrequency

Overview

StringCharacterFrequency is a small Java console program that:

  • Reads a string from the user
  • Counts how many times each non‑whitespace character appears
  • Prints result in the order of the first appearance of each character
  • Repeats until you choose to exit

Example

  • Input: hello world
  • Output: h:1, e:1, l:3, o:2, w:1, r:1, d:1 (the space is ignored)

Features

  • Ignores all Unicode whitespace (spaces, tabs, newlines, etc.)
  • Counts letters (Latin, Cyrillic, …), digits, punctuation, and other non‑whitespace code points
  • Keeps the order of first appearance
  • Simple menu: 1 = continue, 2 = exit (only exact "1"/"2" are accepted)

Requirements

  • Java 21 (Java 17+ also works)
  • Maven 3.9+ (optional, for building/running tests)

Quick Start (with Maven)

From the project root:

# Compile main sources
mvn -q compile

# Run the program
java -cp target/classes StringCharacterFrequency

Run tests:

mvn test

Run without Maven (javac/java)

From the project root:

# Compile into ./out directory
javac -d out src/main/java/StringCharacterFrequency.java

# Run
java -cp out StringCharacterFrequency

Usage example

Enter a string: Hello хелоу
Character counts: H:1, e:1, l:2, o:1, х:1, е:1, л:1, о:1, у:1
Do you want to continue?
1) Yes
2) No
Choose an option (1 or 2) and press Enter: 2
Exiting program. Goodbye!

Notes

  • Whitespace is not counted.
  • Ordering is based on first appearance, not alphabetical order.
  • The program is Unicode‑aware (iterates by code points), so emojis and characters outside the BMP would be handled correctly if entered.

Project structure

StringCharacterFrequency/
├─ pom.xml
├─ README.md
└─ src/
   ├─ main/java/StringCharacterFrequency.java
   └─ test/java/StringCharacterFrequencyTest.java

Troubleshooting

  • If java cannot find the class, ensure you run from the project root and that the -cp (classpath) points to target/classes (Maven) or the directory you compiled to (e.g., out).
  • On older Java versions, make sure your JAVA_HOME points to a JDK (not a JRE).

License

This project is provided as‑is for educational purposes. Use freely.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages