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
Go To First  |  Previous Question  |  Next Question 
 Java  |  Question 913 of 923    Print  
Write a code that returns the number of names in a given array that end in either "ie" or "y"?

  
Total Answers and Comments: 2 Last Update: September 03, 2008     Asked by: brookscsloan 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
August 03, 2008 13:53:57   #1  
srinivasan_81 Member Since: August 2008   Contribution: 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);
  
  
 }
}

 
Is this answer useful? Yes | No
September 03, 2008 14:43:26   #2  
disskyz29 Member Since: August 2008   Contribution: 1    

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

public class Names {
 public static void main (String [] args)

 {
  int count = 0;
  String names[] = {"Valerie", "Jia", "Debbie", "Harvey", "Winslow", "Suzy"  };
  for (int i = 0; i <names.length; i++)
  {
   String a = "y";
   String b = "ie";
   String result;
   result = names[i];
   boolean yChar = result.endsWith(a);
   boolean ieChar = result.endsWith(b);
   if (yChar || ieChar){
    count++;
   }
    
  }
  System.out.println("The number of names ending with ie or y is " + count);
 }
}


 
Is this answer useful? Yes | No

 Related Questions

The Vector class provides the capability to implement a growable array of objects 
Latest Answer : A vector implements dynamic array, which can grow and shrink dynamically.It is similar to Arraylist with a difference that vector can be synchronized. it also contain some legacy methods. ...

When a task invokes its yield() method, it returns to the ready state. When a task invokesits sleep() method, it returns to the waiting state. 
Latest Answer : yield method is mainly used to release the lock of resource and pull up in to steady state from wait pool. Sleep() will pull the thread to sleep for the given time. It will throws exception while trying to intrupt in b/w the sleep state ...

A package statement must appear as the first line in a source code file (excluding blanklines and comments). 
Latest Answer : package statement must appear as the first line in a source code file and one public class declaration. ...

The readLine() method returns null when it has reached the end of a file. 
Latest Answer : readLine() method of BufferReader class returns String and when it reaches the end of file file it returns null. ...

If an expression involving the Boolean & operator is evaluated, both operands areevaluated. Then the & operator is applied to the operand. When an expression involvingthe && operator is evaluated, the 
Latest Answer : & -> for bitwise operation&&-> for logical comparison ...

The finally clause is used to provide the capability to execute code no matter whether ornot an exception is thrown or caught. 
Latest Answer : In try,catch clauses either try clause(If exception is not happend) or catch clause(If exception occures) is exicuted.If we want to exicute a block of statements doesn't depend on exception then we put those block of statements in finally ...

A Java source code file takes the name of a public class or interface that is defined withinthe file. A source code file may contain at most one public class or interface. If a publicclass or interface 

The read() method returns -1 when it has reached the end of a file. 
Latest Answer : It returns null value if its a char type and -1 if its a byte type. ...

It is referred to as the modulo or remainder operator. It returns the remainder of dividingthe first operand by the second operand. 
Latest Answer : 1.For integer remainder operation, where only integer operands are involved, evaluation of the expression (x % y) always satisfies the following relation:x == (x / y) * y + (x % y)2.The floating-point ...

The abs() method is used to calculate absolute values. 


 Sponsored Links

 
Related Articles

Service Oriented Java Business Integration Review

Service Oriented Java Business Integration Review Introduction If you ve read through the texts which give you an introduction to SOA or Web Services you will often find them to be quite frustrating and the reason for this is because they spend too much time referencing business processes which are
 

jQuery Table Row Finished Code

jQuery Table Row Finished Code The Finished Code Our second example page has demonstrated table row striping highlighting tooltips collapsing expanding and filtering Taken together the JavaScript code for this page is mosgoogle geshibot lang php&quot; document ready function var highlighted
 

jQuery Interacting with Other Code

jQuery Interacting with Other Code We learned with our sorting and paging code that we can t treat the various features we write as islands The behaviors we build can interact in sometimes surprising ways; for this reason it is worth revisiting our earlier efforts to examine how they coexist with t
 

jQuery Completed sorting and paging code

Learning jQuery The Finished Code The completed sorting and paging code in its entirety follows mosgoogle geshibot lang php&quot; fn alternateRowColors function tbody tr odd this removeClass even addClass odd ; tbody tr even this removeClass odd addClass even ; return this; ; document
 

code

geshibot lang javascript&quot; head This is a JS snippet from Geshi Bot&quot; Replaces the geshi default classes with mambo joomla classes function replaceGeshiWithMamboClasses if document document getElementsByTagName Category
 

Java and Client Server Models

Java and Client Server Models The Role of Client Servers on the Web Client server models provide the essential mechanisms for working with the Internet In fact most of the World Wide Web is built according to this paradigm In client server models the web browsers run by millions of users are the cli
 

The Interview Snafu

How to turn someone else&rsquo;s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won&rsquo;t get over the line without a polished, prof
 

JavaScript Array Operations

JavaScript Array Operations In this JavaScript tutorial you will learn about different operations with array in JavaScript how to use the for in statement Combining Operations between arrays and within elements of an array joining two or more arrays and joining elements of an arrays along with synta
 

JavaScript Array Object Methods – Part II

JavaScript Array Object Methods Part II In this JavaScript tutorial you will learn about on array object methods slice splice toString shift and unshift methods along with general syntax and examples mosgoogle center slice By using the methods of the array object the programmer is able to retriev
 

Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape