Giter Site home page Giter Site logo

whitespace's Introduction

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 ingmored 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!

whitespace's People

Contributors

kristofer avatar

Watchers

 avatar L. Dolio Durant avatar

Forkers

jaredthacker

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.