Algoritmo que guarda los datos de una URL.
- Ejemplo de entrada: https://page.com/index.html?port=8080&cookie=&host=localhost
- Ejemplo de salida:
port : 8080 cookie : not found host : localhost
- Ejemplo de entrada: https://page.com/index.html?pass=12345&port=8080&cookie=&host=localhost
- Ejemplo de salida:
pass : 12345 port : 8080 cookie : not found host : localhost password : 12345
ALGORITMO:
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String url = scanner.nextLine();
String[] dataOne = url.split("\\?");
String[] dataTwo = dataOne[1].split("&");
ArrayList<String> dataThree = new ArrayList<>();
String password = "";
boolean pass = false;
for (String data : dataTwo) {
String[] dataLine = data.split("=");
if (dataLine.length == 2) {
dataThree.add(dataLine[0] + " : " + dataLine[1]);
if (Objects.equals(dataLine[0], "pass")) {
password = "password : " + dataLine[1];
pass = true;
}
} else {
dataThree.add(dataLine[0] + " : not found");
}
}
if (pass) {
dataThree.add(password);
}
for (String data : dataThree) {
System.out.println(data);
}
}
}