0

Security Problem Tests 3, 6. / Outputs Right in 4 of 6 tests

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner kgb = new Scanner(System.in); String phrase = kgb.nextLine(); int k=0, j=0, front=0, back=0;; boolean var=false; for (k=0 ; k<phrase.length(); k++) { if (((phrase.charAt(k)=='

#x27;)|| (phrase.charAt(k)=='T')) && (front==0)) front=k; if ((front>0) && ((phrase.charAt(k)=='
#x27;) || (phrase.charAt(k)=='T'))) back=k; } for (j=0; j<phrase.length(); j++) if ((phrase.charAt(j)=='G') && ((front < j) && (back > j))) var = true; if (var) System.out.println("quiet"); else System.out.println("ALARM"); } }

14th May 2020, 7:21 PM
Marshall Russell
Marshall Russell - avatar
3 Respostas
0
Hi please share your code or paste the code in description so we could see what's the problem
14th May 2020, 7:24 PM
Abhay
Abhay - avatar
0
Also mention the language name in tags where you have added guard , as well as linking the code in description increases chances of getting help from people with knowledge in this language:-)
14th May 2020, 7:30 PM
Abhay
Abhay - avatar
0
Set front to -1. Because The charecters may also be in 0th position.. And change code accordingly..
14th May 2020, 8:00 PM
Jayakrishna 🇮🇳