In: Computer Science
identify the syntax errors in the following code:
public class Hello {
private static int main(String [] args) {
string Msg=”Hello, Wrld!;
Sytem.out.println(msg+ “Ken")
There are many errors. I am going to list them down 1 by 1.
1. Main method should be public not private.
2. string class in java has a capital S. So it is String not string.
3. double quotes in starting are not correct quotes. and the value of string should also end with double quotes.
4. To print something we use System class not Sytem class.
5. Java is case sensitive so Msg and msg are not same, so we need to change one of those. I am changing the line String msg = "Hello, Wrld!";
6. starting quote before Ken is not correct.
7. Semicolon missing in the println statement at the end.
8. Closing bracket of main method and class are missing, so we need to add two closing brackets.
9. Main method should not return anything. it should return void.
Below is the correct code:
public class Hello {
public static void main(String[] args) {
String msg = "Hello, Wrld!";
System.out.println(msg + "Ken");
}
}
Output