Java Reference
In-Depth Information
Let us correct these errors. After correcting these errors we will rename this program as
ProgramNum2.java . The program after correcting these errors is:
1.
import java.util.*;
2.
3.
public class ProgramNum2
4.
{
5.
static Scanner console = new Scanner(System.in);
6.
7.
public static void main(String[] args)
8.
{
9.
int num;
10.
11.
num = 18;
12.
13.
tempNum = 2 * num;
14.
15.
System.out.println("Num = " + num + ", tempNum = " - tempNum);
16.
}
17.
}
When you compile this program, it will generate the following errors:
ProgramNum2.java:13: cannot find symbol
symbol : variable tempNum
location: class ProgramNum2
tempNum = 2 * num;
^
ProgramNum2.java:15: cannot find symbol
symbol : variable tempNum
location: class ProgramNum2
System.out.println("Num = " + num + ", tempNum = " - tempNum);
^
2 errors
The first error is in Line 13 and it specifies that a symbol cannot be found. The next line
indicates that the symbol is the variable tempNum . If we look at the program, we find that
the variable tempNum is not declared, so we must declare it. The next error is in Line 15
and it also specifies that the variable tempNum cannot be found.
Let us declare the variable tempNum and also rename the program as ProgramNum3.java .
The new program is now:
1.
import java.util.*;
2.
3.
public class ProgramNum3
4.
{
5.
static Scanner console = new Scanner(System.in);
6.
7.
public static void main(String[] args)
8.
{
9.
int num;
Search WWH ::




Custom Search