Write a program to find the length of a string and and reverse it using switch case

class StringDemo
 {
   public static void main(String args[])
    {
      int c=1,b=2;
      String str="kapil";
      int len=str.length();
      System.out.println("Length of string="+len);
      char[] a=new char[len];
      switch(b)
      {
       case 1 :
        { 
          System.out.println("String is");
          for(int i=0;i<len;i++)
           {
            a[i]=str.charAt(i);
            System.out.print(a[i]);
           }
          System.out.println(" ");
        }break;
      case 2 :
        {
         System.out.print("Revaerse string is ->");
         for(int i=len-1;i>=0;i--)
          {
           a[i]=str.charAt(i);
           System.out.print(a[i]);
         
         }break;
  
        }
      default:
      System.out.println("out of switch");

       }
     
   }
   
  }

1 comment:

  1. Thanks for information..Your content is get 1st Rank on this Keyword..Visit my website http://articles-info.com/

    ReplyDelete