Boa noite, eu fiz o desafio buscar CEP, entretanto não sei se é possível melhorá-lo.
package br.com.bucador.cep.api;
import com.google.gson.Gson;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Scanner;
public class BuscadorDeCEP {
public static void main(String[] args) throws IOException, InterruptedException {
Scanner buscarCep = new Scanner(System.in);
System.out.println("Digite o CEP : ");
var cep = buscarCep.nextLine();
String endereco ="https://viacep.com.br/ws/" + cep + "/json/";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(endereco))
.build();
HttpResponse<String> response = client
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
Gson gson = new Gson();
System.out.println(Endereco.class);
}
}