In this Tutorial we want to describe you a code that help you in understanding
the java error message. For this we have a class name java error message. Inside
the class we have a main method that consists of-
1)InputStreamReader-The input stream reader is used to read the byte code
that is used to encode the byte code into character stream.
2)Buffered Reader - The Buffered reader is used to read a
text from a character input Stream reader.
3)readline
-The readline is used to read a number printed by System.out.println on the
output of a command prompt.
On execution of code the program code show an error, identifier expected for
a number, as we do not declare the data type of num. and illegal start of
type as we do not place the braces after the main static method.
javaerrormessage.java
import java.io.*;
public class javaerrormessage {
public static void main(String args[]) throws Exception
InputStreamReader inputStreamReader = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(inputStreamReader);
System.out.println("Enter a number : ");
String num = br.readLine();
int j = Integer.valueOf(num);
for (int i = 0; i < j; i++) {
System.out.println(i);
}
}
}
|
Output
Compiling 1 source file to /home/girish/NetBeansProjects/errors/build/classes
/home/girish/NetBeansProjects/errors/src/javaerrormessage.java:4: ';' expected
public static void main(String args[]) throws Exception
/home/girish/NetBeansProjects/errors/src/javaerrormessage.java:9: <identifier> expected
System.out.println("Enter a number : ");
/home/girish/NetBeansProjects/errors/src/javaerrormessage.java:9: illegal start of type
|
To resolve this error you have to give Brace after public static void main(String args[])throws Exception {