Skip to content

Instantly share code, notes, and snippets.

@Khuzha
Created May 20, 2020 00:01
Show Gist options
  • Select an option

  • Save Khuzha/01f45b21737f25ae61a2a455083cde56 to your computer and use it in GitHub Desktop.

Select an option

Save Khuzha/01f45b21737f25ae61a2a455083cde56 to your computer and use it in GitHub Desktop.
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 Calc {
public static void main(String[] args) throws IOException, InterruptedException {
Scanner scan = new Scanner(System.in);
System.out.println("Введите пример:");
String expr = scan.next().replace("+", "%2B");
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://api.mathjs.org/v4/?expr=" + expr))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment