Hi there,
I've been dealing with this task for two days and the fact is that I think I don't understand what's expected in this task and why my solution has not been validated.
Some help please?
package com.codegym.task.task15.task1527;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/*
Request parser
*/
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
//String line = "http://codegym.cc/alpha/index.html?test=hoho&test2=haha&test3&obj=3.14&nameWithoutVal";
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String URL = "";
try {
URL = reader.readLine();
}catch(IOException e){
System.out.println(e.getCause());
}
String paramPart = "";
String paramObj = "";
for (String parameter : URL.split("\\?")[1].split("&"))
{
if(paramPart.length()==0)
{
paramPart = parameter.split("=")[0] + " ";
} else
{
paramPart = paramPart + parameter.split("=")[0] + " ";
}
if(parameter.split("=").length>1 && parameter.split("=")[1]!="")
{
if(paramObj.length()==0)
{
paramObj = parameter.split("=")[1] + " ";
}else
{
paramObj = paramObj + parameter.split("=")[1] + " ";
}
}
}
System.out.println(paramPart);
//System.out.println(paramObj);
StringTokenizer stringTokenizer = new StringTokenizer(paramObj, " ");
while (stringTokenizer.hasMoreTokens())
{
String nextToken = stringTokenizer.nextToken();
if(nextToken.contains("."))
{
try
{
alert(Double.parseDouble(nextToken));
}catch(NumberFormatException e)
{
alert(nextToken);
}
}
else
{
alert(nextToken);
}
}
}
public static void alert(double value) {
System.out.println("double: " + value);
}
public static void alert(String value) {
System.out.println("String: " + value);
}
}