From f430bcc9f65501d711a700bc83fbee4e99a93efc Mon Sep 17 00:00:00 2001 From: CarlosPerez Date: Fri, 14 Jun 2024 20:39:41 -0700 Subject: [PATCH] #11 - Java --- .../java/chartypes.java" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "Retos/Reto #11 - URL PARAMS [F\303\241cil]/java/chartypes.java" diff --git "a/Retos/Reto #11 - URL PARAMS [F\303\241cil]/java/chartypes.java" "b/Retos/Reto #11 - URL PARAMS [F\303\241cil]/java/chartypes.java" new file mode 100644 index 0000000000..f130d82c3d --- /dev/null +++ "b/Retos/Reto #11 - URL PARAMS [F\303\241cil]/java/chartypes.java" @@ -0,0 +1,32 @@ + +class Main { + public static void main(String[] args) { + String url = "https://retosdeprogramacion.com?year=2023&challenge=0"; + getParams(url); + + } + + public static void getParams(String url) { + String paramsUrl = url.split("\\?")[1]; + String[] keyValueParams = paramsUrl.split("&"); + int paramsSize = keyValueParams.length; + String[] params = new String[paramsSize]; + System.out.print("["); + + for (int i = 0; i < paramsSize; i++) { + String param = keyValueParams[i]; + String value = param.split("=")[1]; + + params[i] = value; + + if (i == paramsSize-1) + System.out.print(", "); + + System.out.print(value); + + } + System.out.print("]"); + + } + +}