Нужна помощь с formatter(новичок)
Нужна помощь у меня есть задание, нужно сделать что-бы когда выводит текст выводился не так:
Euro|EUR|9,006.6631
British Pound Sterling|GBP|7,966.1384
United States Dollar|USD|9,717.7182
А вот так:

Это вроде не сложно, спасибо сразу|
Тут ещё lib: json-20190722.jar вот код:
package com.company;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.stream.IntStream;
import java.util.Formatter;
public class Main {
public static void main(String[] args) throws IOException {
String url = "https://api.coindesk.com/v1/bpi/currentprice.json";
URL obj = new URL(url);
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuffer response = new StringBuffer();
System.out.println(url);
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
response.append('\n');
}
System.out.print(response.toString());
JSONObject jsonObject = new JSONObject(response.toString());
JSONObject bpiObject = jsonObject.getJSONObject("bpi");
for (int i = 0; i < bpiObject.length(); i++) {
String key = bpiObject.names().get(i).toString();
JSONObject currencyObject = bpiObject.getJSONObject(key);
System.out.println(currencyObject.getString("description") + "|" + currencyObject.getString("code") + "|" + currencyObject.getString("rate"));
}
}
}
Ответы (1 шт):
Автор решения: Олексій Моренець
→ Ссылка
System.out.printf(
">%-30s|%-6s|%,14.4f",
currencyObject.getString("description"),
currencyObject.getString("code"),
Double.parseDouble(currencyObject.getString("rate"))
);