W.a.p. to enter and print the reverse of string and pattern enter String:KANPUR o/p should be:RUPNAK in left traingle form.

class ReverseOfString
 {
  public static void main(String args[])
  {
    char s[]=new char[]{'K','A','N','P','U','R'};
    int a=s.length;
  
    for(int i=a-1;i>=0;i--)
     {
     
      for(int j=5;j>=i;j--)
       {
         System.out.print(s[j]);
       }
      System.out.println(" ");
     }
 }
}

No comments:

Post a Comment