Results 1 to 4 of 4
Thread: want to make an array
- 03-28-2009, 08:54 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
want to make an array
i have code to find next string after a particular string that shows result correctly..
right now i want to make an array to show the list of my output's names.
Java Code:FileReader fr; BufferedReader br; String result=""; String word= new String(); String target = "friend"; try{ //read large text file fr = new FileReader ("C:/Users/user/Desktop/java/test.txt"); br = new BufferedReader(fr); Scanner scan = new Scanner(br); while(scan.hasNext()){ result = scan.findWithinHorizon(target,0); if(result!=null) { word = (scan.next() + scan.findWithinHorizon("", 0)); System.out.println(word);output :
rocky
jamila
vicky
jacky
adam
david
-
It's Saturday and I left my crystal ball at work. You may do well to post an actual question, such as what trouble are you currently having? What's working and what's not working?
- 03-28-2009, 10:31 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
actually my program should search a friend name from a txt file and show the similarity scoring.
if i search with the string "vicky" my program should show : named found vicky -100% similar
but if i search with the string "vick" then it will show: named found vicky - 90% simiar... (something like this)
so right now i need an array list that will contain all of my friends name and then my searching word will check entire arraylist one by one to get similarity score.
suppose my txt file contains :
" the name of my childhood friend rocky. in my school life i had a best friend vicky but right now he staying in new zeland. Juile is my college friend and classmate too but new freind jacky is really close to me. i have another on-line friend adam who talk everynight with me. i have lost one friend david last year by raod accident "
so far my code is :
its working but when i search by adam - its showing 100%import java.io.*;
import java.util.*;
import java.lang.*;
class searchCompare2 {
public static double LCS (String S, String T) {
S=S.toUpperCase();
T=T.toUpperCase();
if ((S.equals(""))||(T.equals("")))
return 0;
int[][] num = new int [S.length()] [T.length()];
int maxlen = 0;
for (int i = 0; i<S.length(); i++) {
for (int j=0; j<T.length(); j++) {
if (S.charAt(i) !=T.charAt(j)) num [i][j] = 0;
else {
if (( i==0) || (j==0))
num [i][j]=1;
else num [i][j] = 1 + num[i-1][j-1];
if (num[i][j] >maxlen) {
maxlen = num[i][j];
}
}
}
}
return (2.0*maxlen/(S.length()+T.length()))*100;
}
public static void main(String[] args) throws IOException{
FileReader fr;
BufferedReader br;
String result="";
String word= new String();
String target = "friend";
Scanner scanner = new Scanner(System.in);
String searchname;
String find = "";
try {
fr = new FileReader ("C:/Users/user/Desktop/java/test.txt");
br = new BufferedReader(fr);
Scanner scan = new Scanner(br);
while (scan.hasNext()) { //scan.next();
result = scan.findWithinHorizon(target,0);
if (result !=null)
word = (scan.next()+""+scan.findWithinHorizon("",0));
ArrayList<String> names = new ArrayList<String>();
names.add(word);
for (int i=0; i< names.size() ; i++) {
find = names.get(i);
}
}
System.out.print("Enter your Searching name : ");
searchname = scanner.next();
System.out.println("The similarity score is: ");
System.out.println (searchCompare.LCS(""+searchname , ""+find));
scan.close();
br.close();
fr.close();
}
catch(IOException ex) {ex.printStackTrace();}
catch(StringIndexOutOfBoundsException s){ }
catch(NoSuchElementException nse){}
catch(Exception e){ System.err.println(e.getMessage()); } } }
but if i search with rocky - its showing 0%
also if i search with other name with correct spelling but its showing different value..
can u pls give an idea to solve this prob .................Last edited by doha786; 03-28-2009 at 10:36 PM. Reason: for showing output:
-
Similar Threads
-
String array to byte array?!
By Joe2003 in forum Advanced JavaReplies: 5Last Post: 02-28-2009, 06:09 AM -
How to make a function?
By mephisto772 in forum New To JavaReplies: 5Last Post: 02-23-2009, 09:51 AM -
Reading from a file to make an array
By Bomber_Will in forum New To JavaReplies: 11Last Post: 01-21-2009, 08:19 AM -
simplest way to make 2d array to string
By Tamu in forum Advanced JavaReplies: 4Last Post: 11-25-2008, 04:50 PM -
i need help to make this program
By masaka in forum New To JavaReplies: 2Last Post: 03-23-2008, 01:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks