• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If Else Statements

 
Rykurex Peters
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends, I'm slowly learning but I've ran into another problem, I'll just C&P the code as it describes what the program is intended to do.
The error is a "can't find symbol" pointing to tempwidth and templength, the reason I'm confused is that I thought I wouldn't have to declare these variable, are they not local to the method??

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All variables have to be declared somewhere. If a variable represents part of the state of an object or of the class overall, then it should be declared as a member variable, and its value will survive across method calls. If a variable is only needed as data for a method to operate on, it should be a local variable, declared inside the method or as a parameter.

There is no "undeclared variables are assumed global" rule in Java.
 
Rykurex Peters
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I set the temporary width to width
tempwidth=width

within the method, then if the test is true i was to set width=templength

I'm not sure what part I'm missing as I did include

 
Ivan Franko
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
don't forget to declare variables!

 
Rykurex Peters
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANKYOU!!
Of course it's something so small!
I'll try to compile the main method now and see if everything works smoothly
 
Rykurex Peters
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I'm having another "can't find symbol" error here



In the SortPost.java code I have this



I'm not too sure what to do about this one whereas I noticed the error in the last one straight away.
The line "newSortPost.postType(); " is the problem I think, I just want it to apply the method to it, but not return a value (I think..)

Here is the code for postType()

 
Ivan Franko
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you fix the same issue in switchThickness method?

 
Rykurex Peters
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, yes I did That class compiles properly now, it's just the other one giving me trouble >.<
 
Rykurex Peters
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used this



and now it compiles.. But I have no idea why it works?
Is that declaring the "newSortPost" in some way?
 
Ivan Franko
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why it works?


Because It is ok.

What do you think about idea to read more information about Java Variable Declaration?

For example, here:webpage

I hope, It will be helpful for you.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rykurex Peters wrote:I used this



and now it compiles.. But I have no idea why it works?
Is that declaring the "newSortPost" in some way?


This: declares the newSortPost variable. That is, it says, "Let there be a variable with this type and this name." We have to do this for every variable we want to use in Java. If we don't declare a variable, and just try to use it, then Java says "I don't know what that newSortPost thing is."
 
Rykurex Peters
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot guys, and the link will be really helpful =]!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic