This repository contains a fundamental programming exercise designed to help beginner coders understand the concept of whitespace in both text files and source code. The lab is available in two versions to accommodate different programming languages and learning paths.
java/
- Java implementation using Maven build systempython/
- Python implementation with native file handlingtestdata1.txt
,testdata2.txt
,testdata3.txt
- Sample data files for testing
Whitespace refers to invisible characters that provide spacing and formatting in text. The most common whitespace characters are:
- Space (
' '
) - The character you get when pressing the spacebar - Tab (
'\t'
) - Horizontal indentation character - Newline (
'\n'
) - Line break character - Carriage Return (
'\r'
) - Return to beginning of line
Understanding whitespace is crucial for several reasons:
-
Text Processing: When working with data files, user input, or parsing text, you need to handle whitespace correctly to avoid errors and unexpected behavior.
-
Code Formatting: While most languages ignore extra whitespace in source code, proper use of whitespace makes code readable and maintainable.
-
String Manipulation: Whitespace often needs special handling when comparing strings, validating input, or formatting output.
-
Cross-Platform Compatibility: Different operating systems use different line ending conventions, making whitespace awareness essential for portable applications.
Both versions implement a countBoth
method that manually counts whitespace and non-whitespace characters without using built-in library functions. This hands-on approach ensures students understand what constitutes whitespace rather than relying on abstracted methods.
Students must use loops to examine each character individually, reinforcing fundamental programming concepts while building practical text processing skills.
Choose the Java or Python version based on your current learning focus, but the core concepts and expected outputs remain identical across both implementations.