Buzz Code
Published in

Buzz Code

Java 8 | StringTokenizer Practice 2

Hi y’all! It’s another day to practice the StringTokenizer with me!

You can check my last post out above, and let’s get this started!

[Question 1] Man down!

Let’s say there is a game of the war. And this game records points with the “-”, “+” signs. When there is “-” in front of the number means the player got attacked, and “+” means the player attacked the others.
When there is a String msg that has player’s points, print each of the sum of points that they got and lost.

String msg = "+1/-1/-1/+2/+1/+1/+2/-3/+3";

I split the String with the StringTokenizer war and declared two different named attacked and attack to get the sum of each lost and gotten points. And Here I could use the ASCII code to get the int value from the Strings, but instead I used Integer.parseInt() method that gets the int value from String.
So if there is the String “365”, and you put it as a parameter in this method Integer.parseInt(“365”) like this, you can get the int number 365!

[Question 2] Tongue Twister

String tt = "I thought a thought. But the THOUGHT I Thought wasn't the ThOuGhT I thought I thought.";

There is a tongue twister in the String named tt. Store all the words in the array, and count how many of each of them.
※ It’s the same words even their cases are different.
ex) i-1, thought-7, a-1, but-1, the-2, wasn’t-1

I used one of the String method equalsIgnoreCase() to check if they are the same words, and the split() method to divide the String into word and the count. If the word is not in the ArrayList, I put “word count” in the list and if there is the word I added 1 to the count part!

Well that’s all for today guys! Thank you for reading my post, see ya!

--

--

--

Happy coding!

Recommended from Medium

Backup & Restore Docker swarm

InfinityDB — A NoSQL Multi-Value Database you most know!

Querying Cache in Apache Ignite

From Zero to Hero: The Story of the Native App Development at ImmobilienScout24 I

Deep Dive into Azure Managed Identities — Behind the scenes

Infrastructure as Code at Pocketgems

The Quality Engineering Way To Bulletproof Decisions

DSP digital anti-noise module suitable for airborne communication equipment

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Student Kim

Student Kim

Learn something new everyday.

More from Medium

Assertions In Java

Right Garbage Collector in Java simplified

Cloud Storage, Java

Fundamentals of Java