Why he return -1? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why he return -1?

When i asking index member of massive he return -1, where is mistake? https://code.sololearn.com/cc3nXagTMxHR/?ref=app

22nd Mar 2020, 1:28 PM
Эмиль Маннапов
Эмиль Маннапов - avatar
5 Answers
+ 2
//Just use this code import java.util.*; public class Program { public static void main(String[] args) { Scanner s=new Scanner(System.in); String str=s.nextLine(); str=str.replaceAll("x",""); if(str.contains("$T")||str.contains("T
quot;)){ System.out.println("ALARM"); }else System.out.println("quiet"); } }
9th Apr 2020, 7:09 AM
Ajay
Ajay - avatar
+ 1
Task: Evaluate a given floor of the casino to determine if there is a guard between the money and the thief, if there is not, you will sound an alarm. Input Format: A string of characters that includes $ (money), T (thief), and G (guard), that represents the layout of the casino floor. Space on the casino floor that is not occupied by either money, the thief, or a guard is represented by the character x.
22nd Mar 2020, 1:56 PM
Эмиль Маннапов
Эмиль Маннапов - avatar
+ 1
System.out.print(arr.indexOf(arr.get(i).equals("T"))); Here you are printing array.indexOf(true); Or array.indexOf(false); arr.get(i).equals("T") returns only true or false. Spitting with x.. What happens if G$T doesn't contains x Like G$T TxxG$ $xxxTG
22nd Mar 2020, 4:49 PM
Jayakrishna 🇮🇳
+ 1
Thanks
22nd Mar 2020, 5:07 PM
Эмиль Маннапов
Эмиль Маннапов - avatar
0
Эмиль Маннапов Problem says "Guard" G should be in between money($) and thief(T). If it is like that Print quiet else print Alarm In your code: After splitting, arraylist elements are T, G, $, and spaces. n=[T, G, $,,] and n.equal("GT
quot;) never comes true... You're Wel come...
22nd Mar 2020, 6:01 PM
Jayakrishna 🇮🇳