\t интервал в notepad++ в nppexec
Я написал программу на Java "CircleDemo", которая неизбежно делает это:
System.out.printf("The circle's area \t is \t %.2f \n", circle.getArea());
System.out.printf("The circle's diameter \t is \t %.2f \n", circle.getDiameter());
System.out.printf("The circle's circumference is \t %.2f \n", circle.getCircumference());
В cmd.exe дисплей выглядит так:
The circle's area is 3.14
The circle's diameter is 2.00
The circle's circumference is 6.28
Хорошее, чистое форматирование.
Однако консоль Notepad++ (nppexec) печатает ту же программу, например:
The circle's area is 3.14
The circle's diameter is 2.00
The circle's circumference is 6.28
Вы можете увидеть, как форматирование отличается. Теперь я достаточно долго играл, чтобы выяснить, в чем причина того, что \t по-разному печатает вкладки в cmd.exe и в nppexec Notepad++.
Как я могу отредактировать nppexec форматирование "\t" для печати "\t" так же, как и cmd.exe?
2 ответа
Избегать использования \t
чтобы получить формат массива. Я бы, наверное, просто использовал
System.out.printf("The circle's area is %.2f %n", circle.getArea() );
System.out.printf("The circle's diameter is %.2f %n", circle.getDiameter());
System.out.printf("The circle's circumference is %.2f %n", circle.getCircumference());
Если вам нужно более динамичное решение, вы можете использовать
System.out.printf("The circle's %-13s is %.2f%n", "area", circle.getArea());
или если ответ не всегда должен начинаться с The circle's
System.out.printf("%-26s is %.2f%n", "The circle's area", circle.getArea());
Вы можете попробовать приведенный ниже пример. Используйте "-" перед шириной, чтобы обеспечить отступ влево. По умолчанию они будут иметь правильный отступ; который может не соответствовать вашей цели.
System.out.printf("%-30s %-5s $%.2f\n","The circle's area ", "is" ,circle.getArea());
System.out.printf("%-30s %-5s $%.2f\n","The circle's diameter ", "is" ,circle.getDiameter());
System.out.printf("%-30s %-5s $%.2f\n","The circle's circumference ", "is" ,circle.getCircumference());
Источник: http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html