I'm creating a java program to test if the given string is a comment or not and here's my code so far:
public class comment {
public static void main(String args[]){
String[] com = new String[50];
Scanner scan = new Scanner(System.in);
int i = 2 ,a=0;
System.out.println("Enter comment");
com[i] = scan.nextLine();
if(com[0].equals("/")){
if(com[1].equals("/")){
System.out.println("comment");
}
else if (com[1].equals("*")){
for(i=2;i<=50; i++){
if(com[1].equals("*") && com[i+1].equals("/") ){
System.out.println("comment");
a=1;
break;
}
else{
continue;}}
if(a==0){System.out.println("not");}
}
else{System.out.println("not");
}
}
else{System.out.println("not");
}
}
}
I'm getting an error on this line of code:
if(com[0].equals("/"))
Error says: java.lang.NullPointerException
Any explanation on why is this occuring ?