Language: Java
OS: Windows
IDE: NetBeans 8.0.2
I'm very new at Java and am attempting to teach myself using online resources so I apologize for the newb question and thank's in advance for the help.
My goal: Create a class. Assign a value to a variable. Create a function. Create an object. Call the function to display the variable.
Problem: "error: cannot find symbol test1.printResult(result);"
package usingoperators;
class MathDemo
{
// create integer variable and initiate it to 3
int result = 1 + 2; //result is now 3
// create printResult function with result parameter
void printResult(int result) // result is passed to printResult function
{
System.out.println(result); // prints result
}
}
public class UsingOperators
{
public static void main(String[] args)
{
MathDemo test1 = new MathDemo(); // creates test1 object
test1.printResult(result); // calls the printResult function to print result
}
}
My guess is that I'm not passing "result" to printResult(); correctly.
int resultfromprintResult(int result)as you don't need it. Then in your main method writetest1.printResult();instead.