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
5 Respuestas
+ 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("Tquot;)){
System.out.println("ALARM");
}else
System.out.println("quiet");
}
}
+ 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.
+ 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
+ 1
Thanks
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("GTquot;) never comes true...
You're Wel come...