They don't effect how your code executes.
The printlns are for debugging. To show you what the values of variables are as the code executes.
Type: Posts; User: Norm
They don't effect how your code executes.
The printlns are for debugging. To show you what the values of variables are as the code executes.
public void aMethod() {
int aMethodVar = 0; // define this variable at the method level
System.out.println("1aMethodVar=" + aMethodVar); // show its value here
if (cond) {
int x = 0;...
No, the answer variable will have a value anywhere in the method. It will default to zero and then can be changed anywhere by an assignment statement.
Add printlns to show its value before and...
This doesn't make any sense to me. The variable answer is a method level variable.
I have no idea what you mean by "is bound to". Can you explain?
Your simple example seems to have another...
If the variable only needs to be known in the method with the if statements, define the variable at the method level: inside of the {}s that hold the method's statements and not inside of an {}s...
Same type of problem dealing with the scope of a variable. You need to define the variable at a level that the code in both if statements can see it.
You need to move ALL of the component definitions OUT of the main method to the class level.
Nothing that you define in a method will be known outside of the method.
Defining a variable is not the...
That sounds like an error message from a compiler.
As you gain experience you'll be able to create new classes as needed.
Passing a value to a method or constructor:
objRef.method(answer); // pass answer to the method
AClass aClass = new AClass(answer); // pass answer to the constructor
Example of the...
Not a method, a new listener class.
You will need a reference to the answer variable if you want to use its value.
If answer is a class reference you can pass it to the constructor for the...
Add an action listener to the Answer button. In that listener's actionPerformed method, do what you want done when the button is pressed.
What is done in that listener? Why not set the text...