I want to match input line1 String value and splitLine3 value and if match return True.
Now I got True and False as result if I run multiple times with the same code. I don't know what happened!
Here is output from VS -
PS C:\Users\User\Desktop\Learning Java> c:; cd 'c:\Users\User\Desktop\Learning Java'; & 'C:\Program Files\Java\jdk-16.0.2\bin\java.exe' '-XX:+ShowCodeDetailsInExceptionMessacheese cheese burger cheese Yes No PS C:\Users\User\Desktop\Learning Java> c:; cd 'c:\Users\User\Desktop\Learning Java'; & 'C:\Program Files\Java\jdk-16.0.2\bin\java.exe' '-XX:+ShowCodeDetailsInExceptionMessages' '-cp' 'C:\Users\User\AppData\Roaming\Code\User\workspaceStorage\9c7b2b1e513c6038db76e183d731b494\redhat.java\jdt_ws\Learning Java_3455c92c\bin' 'PaizaRankC1' cheese cheese burger No No
import java.util.*;
public class PaizaRankC1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String line1 = sc.nextLine();
// String line2 = sc.nextLine();
String line3 = sc.nextLine();
String ans = null;
String [] splitLine3 = line3.split(" ");
// System.out.println(Arrays.toString(splitLine3));
// System.out.println(line1.equals(splitLine3[0]));
for (int i = 0; i < splitLine3.length; i++) {
// System.out.println(line1.equals(splitLine3[i]));
// System.out.println(i);
if (line1.equals(splitLine3[i])){
System.out.println(splitLine3[i]);
ans = "Yes";
System.out.println(ans);
// break;
}else{
ans = "No";
System.out.println(ans);
}
}
}
}
I expected if it match return true how many times I run.