Sunday, February 10, 2019

Isc practical 2018(banner problem trick)

Qns-design a program to input names of N teams display them in vertical order.it is required that the name of each team should have a space of 8 placed.
Values of N ___2<N<9.
Example names -
1.MARVEL
2.SYGNUS
3.POLLEN
Output-
     M    S   P
     A     Y  O
     R     G    L
     V     N   L
     E     U    E
     L     S    N

Program----//////
import java.util.*;
class banner
{
     public static void main(String args[])
    {
      Scanner sc=new Scanner(System.in);
      System.out.print("enter values");
      int N,i,stringplace,check;
       char st;
      stringplace=-1;
       check=0;
       boolean t=false;
       N=sc.nextInt();
      String banner[]=new String[N];
       if(N>9)
         {
      System.out.println("invalid input");
         }
     for(i=0;i<N;i++)// arrray input
       {
      banner[i]=sc.next();//enter the teams names
       }
    while(!t)//!t(equals true so it will works)
      { 
      ++stringplace;
       for(i=0;i<N;i++)
          {  
      try{st=banner[i].charAt(stringplace);
       System.out.print(""+st+"       ");
        }
  catch(Exception          StringIndexOutOfBoundsException)
    {
           check++;
  System.out.print("        ");
    }
    }
  if(check>=N)
t=true;
          System.out.println();
  check=0;
}

}
}

No comments:

Post a Comment