Banner

Question 3
The names of the teams participating in a competition should be displayed on a banner vertically, to accommodate as many teams as possible in a single banner. Design a program to accept the names of N teams, where 2 < N < 9 and display them in vertical order, side by side with a horizontal tab (i.e. eight spaces).
Test your program for the following data and some random data:

Example 1:

INPUT: N = 3
Team 1: Emus
Team 2: Road Rols
Team 3: Coyote

OUTPUT

ERC
moo
uay
sdo
t
Re
o
l
s

import java.io.*;
class Banner
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the number of names");
        int n=Integer.parseInt(br.readLine());
        if(n>2 && n<9)
        {
            String name[] = new String[n];
            System.out.println("Enter the names");
            for(int i=0;i<n; i++)
                name[i] = br.readLine();
                
            //find max length of word
            int max=0;
            for(int i=0;i<n;i++)
                if(name[i].length()>max)
                    max=name[i].length();
                    
            //print the names vertically
            for(int i=0;i<max;i++) //for lines
            {
                for(int j=0;j<n;j++) //for each element
                {
                    try{
                    System.out.print(name[j].charAt(i)+"\t");
                    }
                    catch(Exception e)
                    {
                        System.out.print(" \t");
                    }
                }
                System.out.println();
            }
        }
        else
            System.out.println("INVALID RANGE");
    }
}

Leave a Comment

Your email address will not be published. Required fields are marked *