Computer Science, asked by a0335, 8 hours ago

Find the error in the following program and rewrite the program again correctly: public class Hello { public state void mains(String args[]) { System.println(“This is my first java program”); } }​

Answers

Answered by Anonymous
36

Finding Error - Java

First of all, the cօde won't compile, because in the program there are illegal character, that is, double quotation marks [\u201c & \u201d].

Ignoring the double quotation marks and correcting that, the program would compile, but then it would throw a spoj:

spoj: The program compiled successfully, but main class was not found.

Main class should contain method:

⠀public static void main (String[] args)

Now again ignoring the main class and correcting that, the program would compile, but then it would throw a Error now:

Error: Cannot find symbol

⠀System.println("This is my first java program");

symbol: method println(String)

location: class System

This error occurs because the out stream were not used there and this is not inside it. The parameters of the out stream were missing.

The System class and its out stream are used to access the println method.

Adding and correcting that and again recompiling, the cօde would run now.

The given program and corrected program would be like this:

\rule{300}{1}

Given Program:

public class Hello {

public static void mains(String args[]) {

System.println(“This is my first java program”);

}

}

Corrected Program:

public class Hello {

public static void main(String[] args) {

System.out.println("This is my first java program");

}

}

Now, if wanna run the above program, then the output of the above program would be like this:

This is my first java program

Answered by juwairiyahimran18
0

Finding Error - Java

First of all, the cօde won't compile, because in the program there are illegal character, that is, double quotation marks .

Ignoring the double quotation marks and correcting that, the program would compile, but then it would throw a spoj:

spoj: The program compiled successfully, but main class was not found.

Main class should contain method:

⠀public static void main (String[] args)

Now again ignoring the main class and correcting that, the program would compile, but then it would throw a Error now:

Error: Cannot find symbol

⠀System.println("This is my first java program");

symbol: method println(String)

location: class System

This error occurs because the out stream were not used there and this is not inside it. The parameters of the out stream were missing.

The System class and its out stream are used to access the println method.

Adding and correcting that and again recompiling, the cօde would run now.

The given program and corrected program would be like this:

\rule{300}{1}

Given Program:

public class Hello {

public static void mains(String args[]) {

System.println(“This is my first java program”);

}

}

Corrected Program:

public class Hello {

public static void main(String[] args) {

System.out.println("This is my first java program");

}

}

Now, if wanna run the above program, then the output of the above program would be like this:

This is my first java program

Similar questions