Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8344539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:24:19+00:00 2026-06-09T06:24:19+00:00

I am working with free marker and java. I have to output result on

  • 0

I am working with free marker and java. I have to output result on a txt file. Say i have to print for 3 columns as

`A     B      C`

In the similar patter. All three attributes as string.
Condition is that, if the length of string referring to A is more than 3 than it should be printed in the next line. That is if the length is 8 then first 3 character will be in first line, 4 to 6 in second and the remaining two in third. Now after that when I have to print for B, i would have to come back to the first line, but the current position for A will be line 3.

How do i do this?

Example

Hi,                          (required cursor position to print for B).
Hel
lo(current cursor position)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:24:20+00:00Added an answer on June 9, 2026 at 6:24 am

    I don’t know freemarker, Here is one approach by just using String manipulation:

    1. Take a StringBuilder
    2. While A, B or C has any characters left
    3. For A, append extract max 3 characters
    4. append blank spaces till 8 characters
    5. For B, append extract max 3 characters
    6. append blank spaces till 8 characters
    7. For C, append extract max 3 characters
    8. append blank spaces till 8 characters
    9. append newline

    Here is code example, might not be optimized but works:

    public static void main(String[] args) {
      System.out.println(formatOutput("Hello", "How are you?", "Wassup"));
    }
    
    public static String formatOutput(String textA, String textB, String textC) {
        StringBuilder output = new StringBuilder("");
    
        int beginIndex = 0, endIndex = 3;
        String snippet;
        while (textA.length() > 0 || textB.length() > 0 || textC.length() > 0) {
            if (textA.length() > endIndex) {
                snippet = textA.substring(beginIndex, endIndex);
                textA = textA.substring(endIndex);
            } else {
                snippet = textA.substring(beginIndex);
                textA = "";
            }
            output.append(snippet);
            for (int i = snippet.length(); i <= 8; i++)
                output.append(" ");
            ;
    
            if (textB.length() > endIndex) {
                snippet = textB.substring(beginIndex, endIndex);
                textB = textB.substring(endIndex);
            } else {
                snippet = textB.substring(beginIndex);
                textB = "";
            }
            output.append(snippet);
            for (int i = snippet.length(); i <= 8; i++)
                output.append(" ");
    
    
            if (textC.length() > endIndex) {
                snippet = textC.substring(beginIndex, endIndex);
                textC = textC.substring(endIndex);
            } else {
                snippet = textC.substring(beginIndex);
                textC = "";
            }
            output.append(snippet);
            for (int i = snippet.length(); i <= 3; i++)
                output.append(" ");
            output.append("\n");    
        }
        return output.toString();
    }
    

    Output:

    Hel      How      Was 
    lo        ar      sup 
             e y          
             ou?          
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a web based project in my free time. I have
In my free time, I'm working on a risk analysis application. I have already
I have a Registration-Free COM component I developed that is working fine on target
Oh, hi. I'm a junior java developer working in my free time on some
Working with WinForms you have to free memory after using gdi objects, event handlers,
Are there any geo-location api services like hostip.info that working over https Free services
I'm working on a project that is trying to use context-free grammars for parsing
I need to get the free Google charts working over SSL without any security
I've been working with the Apache Mahout machine learning libaries in my free time
I am using CoreGraphics to implement free hand drawing which is working fine for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.