Answer:
So here is the code for which the given statement are required to be retyped correcting the syntax errors.
import java.util.Scanner;
public class Errors {
public static void main (String [] args) {
int songNum = 5;
return; }}
Step-by-step explanation:
Statement 1:
System.out.println("Num: " + songnum);
Error generated:
error: cannot find symbol
Reason:
The reason of this error is that the variable used in the given chunk of code is songNum but the variable used in this statement to display the number is songnum. JAVA is a case sensitive programming language so it will consider both songNum and songnum to be different variables.
Solution:
The correct statement should be:
System.out.println("Num: " + songNum);
As a result of this statement the output will display value of songNum as:
Num: 5
Statement 2:
System.out.println(int songNum);
Errors generated:
error: '.class' expected
error: ';' expected
Reason
These errors come when happen when the compiler detects a missing character in your code. A variable should be declared outside this statement. Int should not be placed here.
Solution:
Remove int from the statement in order to display the value of songNum in output. Correct statement is :
System.out.println songNum);
The output after the statement is corrected:
5
Statement 3:
Error Generated:
error: illegal start of expression
Reason:
The compilers give such an error when it detects something against the JAVA programming syntactical rules. As we can see here that the variable songNum and the string "songs" is not separated correctly.
Solution:
The concatenation between two strings or a variable and a string is done in JAVA by using + operator. So by adding + operator between the two, the error can be resolved.
Correct statement:
System.out.println(songNum+ " songs");
The output after the corrected statement is:
5 songs