I was solving a leet code problem using java and the problem number is “1832. Check if the sentence is pangram”. Before watching the solutions on youtube, I want to try my own code with my own logic in a brute force manner without optimisation. I am Sorry if all this seems silly I am still in the learning phase. In leetcode platform, other online java compilers and IDE’s are showing the same errors.
My Code on the leetcode platform is:
class Solution {
public static boolean checkIfPangram(String sentence) {
char[] arr = new char[26];
char[] arr1 = new char[sentence.length()];
int count=0;
arr={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
for(int i=0;i<arr1.length;i++){
arr1[i]=sentence.charAt(i);
}
for(int i=0;i<26;i++){
for(int j=0;j<arr1.length;j++){
if(arr[i]==arr1[j]){
count++;
break;
}
}
}
return (count==26);
}
}
Line 6: error: illegal start of expression
arr = {‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’,’k’,’l’,’m’,’n’,’o’,’p’,’q’,’r’,’s’,’t’,’u’,’v’,’w’,’x’,’y’,’z’};
^
Line 6: error: not a statement
arr = {‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’,’k’,’l’,’m’,’n’,’o’,’p’,’q’,’r’,’s’,’t’,’u’,’v’,’w’,’x’,’y’,’z’};
^
Line 6: error: ‘;’ expected
arr = {‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’,’k’,’l’,’m’,’n’,’o’,’p’,’q’,’r’,’s’,’t’,’u’,’v’,’w’,’x’,’y’,’z’};
^
3 errors
I tried the same code in IDE:
import java.util.*;
class Main {
public static void main(String[] args){
String a ="thequickbrownfoxjumpsoverthelazydog";
System.out.println(checkIfPangram(a));
}
public static boolean checkIfPangram(String sentence) {
char[] arr = new char[26];
char[] arr1 = new char[sentence.length()];
int count=0;
arr={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
for(int i=0;i<arr1.length;i++){
arr1[i]=sentence.charAt(i);
}
for(int i=0;i<26;i++){
for(int j=0;j<arr1.length;j++){
if(arr[i]==arr1[j]){
count++;
break;
}
}
}
return (count==26);
}
}
But still the same error was shown. Kindly explain why is it showing so!
The error shown in the leetcode platform
2