This source has been modified from my past mini-project...
this source code use to arrange list of data..
by every single character that user input..
please give a comment if have any question or problem...
For java :
import java.util.*;
public class searchSort{
public String []searchData(String []data, String keywords){
int length=data.length;
String []dataStr;
String []tempStr=new String[length];
int counter=0;
boolean similar;
for(int i=0;i<length;i++){
similar=true;
if(keywords.length()<=data[i].length()){
if(keywords.compareToIgnoreCase(data[i].substring(0,keywords.length()))!=0){
similar=false; }
}
else
{
similar=false;
}
if(similar==true){
tempStr[counter]=data[i];
counter++;
}
}
dataStr=new String[counter];
for(int i=0;i<counter;i++){
dataStr[i]=tempStr[i];
}
return dataStr;
}
public static void main(){
Scanner in=new Scanner(System.in);
String []str={ "a" , "b" , "ac" , "d" , "ae" };
System.out.print( "Input a keyword : " );
String key=in.next();
searchSort s=new searchSort();
String []displayStr=s.searchData(str,key);
System.out.println( "Results of Seach :" );
for(int i=0;i<displayStr.length;i++){
System.out.println( "--> " + displayStr[i] );
}
}
}
Sampe Running :
Input a keyword : a
Results of Seach :
--> a
--> ac
--> ae
Created By : Z-man, 2011
No comments:
Post a Comment