ISC 2018 – Computer Practical Question 3 Solution

ISC 2018 Computer 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:
import java.util.*;
public class ISC2018Q3
{
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        String ar[];
        int n, i, j;
        System.out.println("Enter the number of names: ");
        n = sc.nextInt();
        ar = new String[n];
        System.out.println("Enter the names: ");
        for(i=0;i<n;i++)
        {
            ar[i] = sc.nextLine();
        }
        int max = 0;
        for(i=0;i<n;i++)
        {
            if(max<ar[i].length())
            max = ar[i].length();       //Finding the length of the longest string
        }
        System.out.println("OUTPUT:" );
        for(i=0;i<max;i++)
        {
            for(j=0;j<n;j++)
            {
                /*character will be extracted only when i has a value less
                 * than the length of the string else only tabular space will be printed
                 */
                if(i<ar[j].length())
                    System.out.print(ar[j].charAt(i)+"\t");
                else
                    System.out.print("\t");
            }
            System.out.println();
        }
    }
}
OUTPUT:

No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...