Ask Question

Retype the statements, correcting the syntax errors.

System. out. println ("Num: " + songnum);

System. out. println (int songNum);

System. out. println (songNum " songs");

+3
Answers (1)
  1. 13 February, 20:52
    0
    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; }}

    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
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Retype the statements, correcting the syntax errors. System. out. println ("Num: " + songnum); System. out. println (int songNum); System. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers