GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  J2EE  >  Java

 Print  |  
Question:  Write a code that returns the number of names in a given array that end in either "ie" or "y"?



August 08, 2008 13:53:57 #1
 srinivasan_81   Member Since: August 2008    Total Comments: 2 

RE: Write a code that returns the number of names in a given array that end in either "ie" or "y"?
 
The below code produces the output along with the names that have the conditions:
class StringTest
{
 public static void main(String[] args)
 {
  String s[]={"jennie","pety","jenifer"};
  int count =0;
  for (int k = 0;k<s.length;k++ )
  {
   String s3=s[k];
   int i=s3.length();
   
   char s1=s3.charAt(i-1);
   
   char s2=s3.charAt(i-2);
   
   if (s1=='e'&& s2=='i')
   {
   System.out.println("The Name which has ending letters as ie :" +s3);
   count = count+1;
   }
   else if(s1=='y')
    {
   System.out.println("The Name which has ending letter as y :" +s3);
   count = count+1;
   }
   
  }
  System.out.println("Total Names which have ending letters as 'ie' or 'y ' =" + count);
  
  
 }
}
     

 

Back To Question