Banner Program ISC Computer Science 2018 Practical

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:

E       R       C
m       o       o
u       a       y
s       d       o
                t
        R       e
        o
        l
        s
Example 2:
INPUT:
N = 4
Team 1: Royal
Team 2: Mars
Team 3: De Rose
Team 4: Kings
OUTPUT:
R       M       D       K
o       a       e       i
y       r               n
a       r       R       g
l       s       o       s
                s
                e
Example 3:
INPUT:
N = 10
OUTPUT:
INVALID INPUT

import java.util.Scanner;
class Banner{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("N = ");
        int n = Integer.parseInt(in.nextLine());
        if(n < 3 || n > 8){
            System.out.println("INVALID INPUT");
            return;
        }
        String a[] = new String[n];
        for(int i = 0; i < a.length; i++){
            System.out.print("Team " + (i + 1) + ": ");
            a[i] = in.nextLine();
        }
        String l = a[0];
        for(int i = 1; i < a.length; i++){
            if(l.length() < a[i].length())
                l = a[i];
        }
        for(int i = 0; i < l.length(); i++){
            for(int j = 0; j < n; j++){
                if(i < a[j].length())
                    System.out.print(a[j].charAt(i) + "\t");
                else
                    System.out.print("\t");
            }
            System.out.println();
        }
    }
}

Comments

Popular posts from this blog

Encrypt Program ISC Specimen 2023 Theory

No Repeat Program ISC Computer Science 2022 Semester 2 Theory

Bank Inheritance Program ISC Specimen 2023 Theory