• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please explain why I get "cannot find symbol" error in Stdin and Stdout Statement in the code below  RSS feed

 
Sudeep Choudhari
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ganesh Patekar
Bartender
Posts: 726
23
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Because compiler can't find the declaration of reference variables Stdin and StdOut on which you are invoking readString() and printf() methods. What are the type of these variables, you haven't declared them anywhere in your program. Please always quote from where you got this click here ---> QuoteYourSources
 
Sudeep Choudhari
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a java challenge from https://www.hackerrank.com/challenges/java-end-of-file
Sudeep Choudhari wrote:
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

Please always indent your code correctly; look at lines 7 and 15 which are indented completely differently. The indentation is there so you can read your own code, and you will confuse yourself if you don't indent it properly.
Don't import all those packages; you are only using java.util.Scanner.
And look at line 12 where you have two declarations on the same line. Those are all features you can use to confuse yourself.
Look at line 19. There must be a simpler way to put that inequality. It is not at all obvious what it means.
Where did you find StdIn and StdOut? They are not terms used in Java® programming, but common in C/C++ programming.

If you ever get the code to compile you will have a nasty surprise with the loop in line 14. Since System.in is always open, that loop will run for ever ... or at least until an exception stops it.
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:If you ever get the code to compile you will have a nasty surprise with the loop in line 14. Since System.in is always open, that loop will run for ever ... or at least until an exception stops it.

It will die on line 16 because str has not been initialized.
 
praveen kumaar
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello sudeep,
actually i have just gone through your code,their i found some bad practice listed below:
1.Importing the unnecessary package
their are packages in your code (which are imported) but not been used.actually it just confuse one why have you make a import of such package,so make it your habit not to do so.

2.Importing the whole package
try not to import the whole package like import "java package.*" but instead import just the necessary class of the package.it doesnot have to do anything with performance or any overhead cost.actually keeping the things straightforward,clean and as of less ambiguity as possible is a good practice.with an exception,you have to type more.

try to write your code indently
this part is allready been covered by "campbell".

Now come to your problem:
Arrays are object too,so they need to be instantiated before use.

Hope it helps!
kind regards,
praveen
 
Ganesh Patekar
Bartender
Posts: 726
23
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:
Campbell Ritchie wrote:If you ever get the code to compile you will have a nasty surprise with the loop in line 14. Since System.in is always open, that loop will run for ever ... or at least until an exception stops it.

It will die on line 16 because str has not been initialized.
If we consider str has not been initialized then It will not even compile as It is a local variable which must be initialized before use.
 
Aline Galea
Greenhorn
Posts: 22
2
IntelliJ IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

The Princeton online textbook on java programming uses StdIn and StdOut classes. Those were made for the sake of making some tasks easier to understand: http://introcs.cs.princeton.edu/java/stdlib/
I assume you have taken these statements from this textbook thinking it was standard java, but it is not. You can't make those work for the Hackerrank practice challenges, as you can't add extra classes as far as I'm aware. It's the reason for the "cannot find symbol" error, the compiler complains because it can't find those classes.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

That is useful information; maybe the hackerrank site doesn't make it clear where those classes come from.
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HackerRank shell code looks like this:

Beginning exercises teach you how to read data in and print it out.
 
Ganesh Patekar
Bartender
Posts: 726
23
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nah! here they do mention about what these stdin and stdout is about but I think use of such abbreviations create confusion --->Java Stdin and Stdout They closed Scanner I find that Starnge practice.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code snippet doesn't use stdin or stdout, nor StdIn and StdOut. It uses STDIN and STDOUT. I hope they take that to mean everybody knows what those C style abbreviations mean. And they have managed to mislead at least one user. It does however say System.in earlier.

I would suggest that trying to read from System.in until you read end‑of‑file is poor programming, since you would have to close System.in.
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aren't these challenges just rewritten ones from their C ones?
That would explain the use of STDIN and STDOUT which are not commonly found terms in Java.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!