Why the compiler can not find the symbol?
I am tryuibg to compile the following using Netbeans.
Code :
public class Example1 {
public int sumOfDigits(int n)
{
int sum = 0;
n = Math.abs(n);
while (n > 0)
{
sum += n % 10;
n /= 10;
}
return sum;
}
public void inputAndProcess(Input in)
{
System.out.print("Type an integer: ");
int n = in.nextInt();
System.out.print("The sum of the digits of: " + n);
System.out.println(" is: " + sumOfDigits(n));
}
// The main method should do no more than create the object
// and call a method to do the work.
public static void main(String[] args)
{
new Example1().inputAndProcess(new Input());
}
}
The compilation gives me 2 errors (actually the same error twice) :
Can NOT find Symbol class Input location class Example1
I am using the latest Java JDK. What should I do? Please help. :confused:
Re: Why the compiler can not find the symbol?
Input isn't a default Java API class. You either need to write it yourself or get it from someone. If you want to just get input from the user, try using a Scanner object:
Code :
public void inputAndProcess(Scanner in)
{
// your code above is fine
}
public static void main(String[] args)
{
new Example1().inputAndProcess(new Scanner(System.in);
}