[완료]Java :: 형식화된 콘솔출력이 궁금합니다.

APRIL1024의 이미지

숙제를 하던中 복병을 만났습니다.

C style에선 printf("%10s\n", s); 이렇게 하면 되는데, Java에선 어떻게 해야 할까요? 포맷터를 이용 하라고 나온걸로 이해했는데, 몇시간 동안 찾아봐도 해결책을 찾지 못 해서 이렇게 도움을 구합니다.

Q. 스트링을 토큰으로 분리하여 콘솔에 줄 맞춰 출력 하려고 합니다. 어떻게 줄을 맞춰야 할까요?

slomo의 이미지

Formatter 말씀을 하시니 1.4는 아니신 것 같은데요...
Java 1.5에서는 그냥 System.out.printf("%10s\n", s);
하셔도 될텐데요...
====
No one asks you for change or directions.
-- Slo-Mo, J. Krokidas

====
No one asks you for change or directions.
-- Slo-Mo, J. Krokidas

APRIL1024의 이미지

The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, String)

이런 에러가 뜨는데.. Object[]가 와야 한다는데요.. 잠을 자야겠어요. -_-;;

카二리의 이미지

이클립스 프로젝트 설정에서 JDK 설정을 1.4에서 1.5로 바꿔 주세요.
기본 설정이 1.4 일텐대 그렇게 되어 있을 때 저런 에러가 뜹니다.

새 생각 :)

새 생각 :)

mr.lee의 이미지

에러가 안나는듯 합니다만.

public class T
{
  public static void main (String[] args)
  {
    String s = "Good";
    System.out.printf ("%10s\n", s);
  }
}

jiggol의 이미지


System.out.println(s+"\t"); 한 번 해보세요..
c언어 방식의 정렬법은 저도 모르겠고.. 출력할때 마지막에 "\t" 를 붙여주니 알아서 해주더군요

APRIL1024의 이미지

감사드립니다. 임시 방편이라도 저렇게 쓰니 좋네요.

정확한 포맷 사용방법 아시는 분 없나요? ㅡ.ㅠ

gamdora의 이미지

JavaSE 버전이 어떻게 됩니까?

APRIL1024의 이미지

환경을 적지 않았네요.. (__)

JDK 1.6 입니다. 최신버전 깔았구요.

superwtk의 이미지

System.out.printf()

JDK 1.5 부터 지원됩니다.

--------------------------------------------------------------------------------
http://blog.superwtk.com

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.