Page 641 - Computer science 868 Class 12
P. 641

Program 27    Print team Name Vertically
                                 Define a class Team which have a following variable and method.
                                 Data Members
                                 int n                        :  to store number of team
                                 String t[]                   :  array variable to store the name of the team
                                 int l                        :  to store the position of the team having the longest name
                                 Member Functions
                                 void input ()                :  to input data
                                 void output ()               :  to print the names of the team in a single banner.

                   1       import java.util.*;

                   2       class banner
                   3       {

                   4       static Scanner sc=new Scanner(System.in);
                   5        int n;

                   6       String name[];
                   7

                   8       void input()
                   9       {

                   10      System.out.print("N = ");
                   11      n=sc.nextInt();

                   12      name=new String[n];
                   13      for(int i=0;i<n;i++)

                   14      {
                   15      System.out.print("Team "+(i+1)+": ");
                   16       name[i]=sc.next();

                   17          }

                   18      }



                   19      void output()

                   20       {
                   21      int l=name[0].length();

                   22      for(int j=0;j<n;j++)
                   23       {

                   24      if(l<name[j].length())
                   25       l=name[j].length();





                                                                                                                       639
                                                                                                   Internal Assessment  639
   636   637   638   639   640   641   642   643   644   645   646