A student has written the following program to find the sum of two numbers:-
public class sum
{
public static void SampleMethod()
{
int first = 20;
int second = 40
System.out.println("Sum is: + first + sec0nd);
}
}
___
Identify all the syntax errors.
Answers
Corrected códe:
A student has written the following program to find the sum of two numbers.
public class sum
{
public static void SampleMethod()
{
int first = 10;
int second = 20
System.out.println("Sum is: + first + second);
}
}
Understand about syntax errors:
Syntax errors are those errors which used to occurs due to wrong following of syntax of programming language. They usually occurs typically by doing a common spelling or grammatical mistakes. In english only not any other language. After the códe is runed compiler identifies it on the spot and prevents the program from going to run.
It's a type of arranging tokens inorder to create well-formed statements
Some syntax errors:
By assigning a string value in a integer variable
- Wrong spelling
- Unmatched brackets
- Incorrect identifiers
- Usage of assignment operator that is equals to (=) instead of using an equality operator(==)
Syntax errors which occurred:
Line 6 : Missing semicolon here:
int second = 20
Line 7 : Println should be in capital letter that is P otherwise it would be wrong.
There are more syntax errors in this line those are-
There should be a closing quotation mark:
"Sum is:"
And the spelling is wrong of second it is written as Sec0nd it should be Second.
Additional information:
Errors in a computer program are the mistakes which occur and totally disturb the program and remove him from the path of its normal working.
It is widely also known as bugs.