Results 1 to 2 of 2
  1. #1
    baltimore is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default Help me with system.out.println

    Hi, I have a code:

    Java Code:
    System.out.print(strWord.substring(0,1));
    for (intCounter = 1; intCounter <= intStringLength-1; intCounter++){
    					
    intCounter2 = intCounter + 1;
    strSubFinalWord = strWord.substring(intCounter,intCounter2);
    strFinalWord = "-" + strSubFinalWord;			
    					
    System.out.print(strFinalWord);
    }
    System.out.println("");
    is it possible to not do a lot of system.out.println and system.out.print n make a string that would equal to the final product of the above.
    Thanks.

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Use a StringBuilder
    Java Code:
    intStringLength = strWord.length();
    StringBuilder sb = new StringBuilder();
    sb.append(strWord.substring(0,1));
    for (intCounter = 1; intCounter <= intStringLength-1; intCounter++)
    {
    intCounter2 = intCounter + 1;
    strSubFinalWord = strWord.substring(intCounter,intCounter2);
    strFinalWord = "-" + strSubFinalWord;
    					
    sb.append(strFinalWord);
    }
    System.out.println(sb.toString());

Similar Threads

  1. System.out.println
    By sunjavaboy in forum Advanced Java
    Replies: 3
    Last Post: 03-22-2008, 02:30 AM
  2. Template for System.out.println
    By eva in forum Eclipse
    Replies: 3
    Last Post: 01-05-2008, 01:46 PM
  3. shortcut of System.out.println() without netbeans
    By VipinKeshri in forum New To Java
    Replies: 1
    Last Post: 11-18-2007, 10:24 AM
  4. Eclipse - shortcut to System.out.println
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-07-2007, 05:21 PM
  5. System.out.println shortcut
    By ravian in forum Eclipse
    Replies: 2
    Last Post: 11-07-2007, 11:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •