I think my code is pretty correct, but the only thing which could be wrong is the requirement, and it is so confusing because it doesn't give more test cases for what exactly is a right output. Need help, thx guys.
My understanding is the information splits with & and will output the first line before "=",
then alert(substring after "=" and before next "&" like 1v1=15 , which 1v1 will be the first line).
package com.codegym.task.task15.task1527;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Request parser
*/
public class Solution {
public static void main(String[] args) {
//write your code here
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = reader.readLine();
int index = indexOf(line,'?');
String temp = "";
String sum = "";
String[] split = line.substring(index+1,line.length()).split("&");
double single = 0.0;
for(String a:split){
if(a.contains("=")){
String str = a.substring(0,indexOf(a,'='));
temp += str+" ";
}
else{
temp += a+" ";
}
}
System.out.println(temp.trim());
for(String a: split){
if(a.contains("=") && !split[split.length-1].equals(a)){
String check = a.substring(indexOf(a,'=')+1,a.length());
if(check.contains(".")){
try{
double num = Double.parseDouble(check);
alert(num);
}
catch(Exception e){
alert(check);
}
}
else{
if(!Digit(check)){
alert(check);
}
}
}
}
reader.close();
}
catch(Exception e){
}
}
public static boolean Digit(String a){
for(int i = 0;i < a.length();i++){
if(!Character.isDigit(a.charAt(i))){
return false;
}
}
return true;
}
public static int indexOf(String a,char b){
int index = -1;
for(int i = 0;i < a.length();i++){
if(a.charAt(i) == b){
index = i;
break;
}
}
return index;
}
public static void alert(double value) {
System.out.println("double: " + value);
}
public static void alert(String value) {
System.out.println(value);
}
}