I am working on problem of string manipulation.Following is my code snippet.
I am really not sure why my code control is not going inside IF
loop.
public class test{
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int searchVariable = scan.nextInt();
int numberOfValues = scan.nextInt();
scan.nextLine();
while (numberOfValues-- != 0) {
String strg = scan.nextLine();
String[] arrayInt = strg.split(" ");
for (int i = 0; i < arrayInt.length; i++) {
// System.out.println("test 1===");
// System.out.println("i value" + i);
// System.out.println("i " + strg.charAt(i));
// System.out.println(searchVariable);
if (searchVariable==strg.charAt(i)) {
System.out.println("===>");
System.out.println("index " + i);
return;
}
}
}
}
}
Input
4
6
1 4 5 7 9 12
Output
output should be 4. As i am writing this code for finding integer 4 in the third line of input.
Problem
Program control is not going inside the loop if (searchVariable==strg.charAt(i))
.Please help!!