Comments (5)
Nice test-case. The leading "@@@" in the string seems to break the code. I have updated the solution and it will now work with your testcase. Thanks.
from hackerrank_solutions.
Thank you for taking the time to fix it. Now I have follow-up questions.
I designed a customized test case where the input is three spaces. I tried your updated solution and my own on Hackerrank. Both incurred an error:
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1540)
at Solution.main(Solution.java:8)
Line 8 is provided in the original stub code: String s = scan.nextLine();
However, if I run the same program (yours or mine) on my local machine (Ubuntu Linux with openjdk version "1.8.0_191"), there is no error. A customized input of three spaces leads to an output of 0 with no tokens printed, which is what one would expect. So now my question is why would Hackerrank produce such an error for this customized input. Just FYI, an input of null (meaning pressing the return key without entering anything) has the same behavior.
If you have time and are interested in looking into this, I'd like to know what you think of it. Thanks.
from hackerrank_solutions.
Good job solving on this extreme edgecase. If your input is just 3 spaces as " ", then scan.nextLine() cannot find a line to return since it skips over all whitespace. In your case you handle it perfectly. Since they don't specifically ask to test for input without letters, and didn't test for it explicitly in their own tests, I'm okay with assuming they intended us to solve the problem for input that always contains letters.
from hackerrank_solutions.
I probably didn't make myself clear enough. My question really is about this. Hackerrank compiler produces an exception for the extreme case (which I agree is probably unintended). But the compiler on my own computer (with openjdk 1.8.0_191) gives no error/exception for the same exact code and produces the expected output. So should I just assume that this discrepancy is caused by use of different Java compilers, which handle situations differently? I don't know much about how Java works under the hood. Hence my latest question.
Thanks again for taking the time and effort responding.
from hackerrank_solutions.
Scanner's .nextLine() should return NoSuchElementException if no line is found, so I'm not sure why it works on your compiler.
from hackerrank_solutions.
Related Issues (13)
- Problem Changed HOT 1
- wrong HOT 5
- How do you generate directory for this project? HOT 1
- Solution of Weather Observation Station 8 seems wrong
- does not work correctly with input set 2 from hackerrank HOT 1
- why this input is false ? HOT 1
- Let's add C++ solutions HOT 3
- Hackerrank
- Please I need hecker command HOT 1
- Java Regex 2 - Duplicate Words
- Tag Content Extractor has an imprecise statement
- Java List is bad teaching
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hackerrank_solutions.