java - Code to tell whether a string is a Pangram or not? -
import java.io.*; import java.util.*; public class solution { public static final int n = 26; public int check(string arr){ // int count = 0; if(arr.length() < n){ return -1; } for(char c = 'a'; c <= 'z' ; c++){ if((arr.indexof(c) < 0) && (arr.indexof((char)(c + 32)) < 0)){ return -1; } } return 1; } public static void main(string[] args) { scanner s1 = new scanner(system.in); string s = s1.next(); solution obj = new solution(); int d = obj.check(s); if(d == -1) system.out.print("not pangram"); else system.out.print("pangram"); } }
if string entered : "we promptly judged antique ivory buckles next prize" gives wrong output " not pangram" m not able find out wrong code thanx in advance !
the problem whitespace separator scanner.next()
. when input we promptly judged antique ivory buckles next prize
, s
point string we
. when call obj.check(s)
on we
return -1
.
to verify case, can print s
, check value. can do:
string s = "we promptly judged antique ivory buckles next prize";
call obj.check(s)
, see return correct answer.
to fix should call scanner.nextline()
instead of scanner.next()
:
string s = s1.nextline();
Comments
Post a Comment