What am I doing wrong here?
package com.codegym.task.task15.task1527;
import java.io.*;
import java.util.*;
/*
Request parser
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> arrL = new ArrayList<String>();
int flag = 0;
String s = reader.readLine();
//find the index where ? starts
int indexSave = 0;
for (int i = 0; i < s.length(); i++) {
Character c = s.charAt(i);
if (c.equals('?')) {
//save the index
indexSave = i;
break;
}
}
//make a substring that starts after the ?
String z = s.substring(indexSave + 1);
String[] arr = z.split("&");
for (String x : arr) {
arrL.add(x.substring(0, x.indexOf("=")));
}
//print the array!
for (int i = 0; i < arrL.size(); i++) {
if (i == arrL.size() - 1) {
System.out.print(arrL.get(i));
if (arrL.get(i).equals("obj")) {
flag++;
}
}
else {
System.out.print(arrL.get(i) + " ");
if (arrL.get(i).equals("obj")) {
flag++;
}
}
}
System.out.print("\n");
//call alert based on flag
if (flag >= 1) {
try {
for (int i = 0; i < arr.length; i++) {
if (arr[i].startsWith("obj")) {
String b = arr[i].substring(arr[i].indexOf("=") + 1);
//try to convert to double from String
Double d = Double.parseDouble(b);
double e = d.doubleValue();
alert(e);
}
}
} catch (NumberFormatException f) {
for (int i = 0; i < arr.length; i++) {
if (arr[i].startsWith("obj")) {
String b = arr[i].substring(arr[i].indexOf("=") + 1);
alert(b);
}
}
}
}
}
public static void alert(double value) {
System.out.println("double: " + value);
}
public static void alert(String value) {
System.out.println("String: " + value);
}
}