I've been scouring the internet for hours trying to piece this one together. My code feels sloppy, I'm exhausted, and I know it has to do something with the alert(String value) method. Can someone prod me in the right direction? I feel so freakin' stupid.
package com.codegym.task.task15.task1527;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
/*
Request parser
*/
public class Solution {
public static void main(String[] args) throws IOException {
URL url = null;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
url = new URL(reader.readLine());
String _Query = url.getQuery();
String[] arrOfStr = _Query.split("&");
for (String a : arrOfStr) {
if (a.contains("=")) {
int index = a.indexOf("=");
a = a.substring(0, index);
System.out.print (a + " ");
}
}
System.out.println();
for (String a : arrOfStr) {
if (a.contains("=")) {
int index = a.indexOf("=");
a = a.substring(index + 1);
try {
alert(Double.parseDouble(a));
}
catch (NumberFormatException e) {
alert(a);
}
}
}
}
public static void alert(double value) {
System.out.println("double: " + value);
}
public static void alert(String value) {
System.out.println("String: " + value);
}
}