প্রেজেন্টেশন এরর পাওয়ার কারণটা ধরতে সাহায্য দরকার।

সমস্যা : Justifier II

সমাধান :

import java.util.Scanner;

public class Main
{
     public static void main(String[] args)
     {
        Scanner input = new Scanner(System.in);
        String[] lines;
        int n, maxLength;

        while ((n = input.nextInt()) != 0)
        {
            input.nextLine();

            lines = new String[n];
            maxLength = 0;

            for (int i = 0; i < n; i++)
            {
                lines[i] = input.nextLine().trim().replaceAll("\\s{2,}", " ");

                if (lines[i].length() > maxLength)
                {
                    maxLength = lines[i].length();
                }
            }

            for (String line: lines)
            {
                printSpace(maxLength - line.length());
                System.out.println(line);
            }

            System.out.println();
        }
    }


    public static void printSpace(int n)
    {
        for (int i = 1; i <= n; i++)
        {
            System.out.print(' ');
        }
    }
}

asked 01 Jul, 10:39

sksuranjit's gravatar image

sksuranjit
8511

edited 01 Jul, 12:34

Mosharraf%20Hosain's gravatar image

Mosharraf Hosain ♦
1.0k18

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×214

question asked: 01 Jul, 10:39

question was seen: 87 times

last updated: 01 Jul, 12:34