Skip to content

ZipCodeCore/WhiteSpace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WhiteSpace

What is whitespace in coding? What is whitespace in a text file? Well, we are told that whitespace doesn't matter in Java.

Yes. a space character is whitespace (like in this string, between the double quotes, " " there is One space)

And YO, when you see a string "A string", the double quotes define, delimit, the string. They are not part of the string. You'll see the word delimiter to describe the beginning and the end of strings. Delimiter means the " or ' around the string (yes, in some langues you can use a single quote or double quote). More on what you do if you need to put a double quote INSIDE a string later.

There are a few test data files in the top level of this repo. Write a method in class Whitespace called countBoth(String input) that prints out the number of whitespace characters found, and the number of non-whitespace characters found. Your output should match the answers below.

You are _not allowed to use the Character.isWhitespace() method in your solution. (But you should read about it, so you know what you're trying to write.)

If the input string is "This is a string." your countBoth should print

3, 14

Notice the comma! And Notice how the double quotes are ignored by the counting method.

If the data file contains

Zip Code Wilmington
creates
Great Coders.

Output should be....

5, 34

(Yes, really)

when you read in the testdata files, your program should print

5, 36
52, 276
234, 1089

as output. first line is testdata1, then 2, then 3.

On Whitespace

When I asked Github CoPilot to describe whitespace with respect to Java, it helpfully wrote:

In Java, whitespace refers to one or more non-printable characters such as:

  • ' ' (space)
  • '\t' (tab)
  • '\n' (new line)
  • '\r' (carriage return)

These characters are used to format the code for better readability. They separate tokens in the Java source code, but the Java compiler generally ignores them. For example, the following two lines of code are equivalent:

int x = 10;
int     x    =    10;

In both cases, the Java compiler ignores the extra whitespace and treats both lines as identical.

Postscript

ONE of the key learnings here is understanding those extra characters, newline and carriage return, and how they are interpreted.

Yep, this zipcode stuff is gonna be fun!

About

what is whitespace in coding?

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages