i am having this problem , i have 8 strings say
( boy,topped,pens,remotes ,boted ,toyed, car,house)
but i am looking for 3 strings having substrings ending with a (ed,s,s )
for exapmle topped,pens,remotes

however i have to check by first checking the first string boy and i throw it away and go to the next and i find that it ens with the ed so i keep it in the array or any data structure i check the next work if it has s if the next word in the sequency has s then i continue with the third and the fourth topped,pens,remotes
and once i get that patter i can throw print the words out however the next words show that it has a ed so i insert in in the data structure and i check the next word which is not s so i have to drop boted and if toyed dint have s but it has ed is insert it as first and continue in that format ...its like a rolling bed

how can i develope this kind of program in java. any genius

Recommended Answers

All 3 Replies

Do you have any code so far?

/*
the input file is like this
facebookkkkk benzllll iphoneyyyy microsoftkkkk wikipediawwww dellyyyy sonypppp hpllll compaqkkkk lgwww ferarikkkk motolora bbbb
// so we read TOKEN by TOKEN but we need to get any combination of of 3 TOKEN ending with (kkkk wwww yyyy )
and they must be following each other
for example microsoftkkkk wikipediawwww dellyyyy
but wen we go to sonypppp WE DROP IT BECAUSE ITS NOT CANDIDATE
hpllll
compaqkkkk WE KEEP THIS IN THE DATA STRUCTURE AND SEE IF THE NEXT IS WWWW
IN THIS CASE NEXT TOKEN IS
lgwww SO WE KEEP IT NO WE HAVE compaqkkkk lgwww
WE CHECK IF NEXT TOKEN IS HAVING YYYY SO WE DONT HAVE IT
SO WE THROW AWAY THE TWO SRINGS compaqkkkk lgwww COZ THE NEXT IS FERARI
SO WE CHECK THE FERARI TOKEN TO SEE IT IT CAN TAKE UP THE FIRST PLACE
AND YES IT CAN SO WE DONT THROW IT ME MOVE IT TO THE FIRST PLACE

ferarikkkk
AND NEXT TOKEN IN LINE IS NOT HAVING WWWW SO DEFINATELY WE THROW AWAY THE
FRIST AND CHECK THIS SECOND IF IT CAN TAKE UP THE FIRST PLACE
NOTE// THE STRINGS HAVE TO BE NEXT IN LINE TO EACH OTHER TO QUALIFY MAKING UP THE PATTERN KKKK WWWW YYYY

// so
*/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import java.util.HashMap;
import java.util.StringTokenizer;

public class readfile {


	public static void main(String[] args) throws IOException {
		FileReader inputStream = null;
		FileWriter outputStream = null;

		try {
			inputStream = new FileReader("input.txt");
			outputStream = new FileWriter("output.txt");
			BufferedReader br = new BufferedReader(inputStream);
		
			String line;
			while ((line = br.readLine()) != null) {
     			String stringtoken;
				StringTokenizer st = new StringTokenizer(line);
				while (st.hasMoreTokens()) {
					stringtoken = st.nextToken();
					//now the stringtoken contains a string 
					String[] strAray= new String[3];
					strAray[0]=stringtoken;
		            strAray[1]=st.nextToken();
					strAray[2]= st.nextToken();
					if ((stringtoken.endsWith("KKKK")) && (strAray[1].endsWith("wwww")) && (strAray[2].endsWith("yyyy")))
					{

												
						// System.out.println( + "strAray[0]" + "strAray[1]" + "strAray[2]");
						}
						
						else 
						
						//check if second token qualifies for the first position and thrid token qualifies for the second position 
						// and collect the next token and see if it makes a pattern
						
						if (strAray[1].endsWith("kkkk"))
						            strAray[0]=strAray[1];
						           if (strAray[2].endsWith("wwww"))
						          {
						             strAray[1]=strAray[2];
									   strAray[2]= st.nextToken();;
									if(strAray[2].endsWith("wwww"))
	
						// System.out.println( + "strAray[0]" + "strAray[1]" + "strAray[2]");
						              
						   
						try 
						{
								 System.out.println(" " + "\n");
								 outputStream.write(" " + "\n");
							  
							  }
							
							
						 catch (Exception e)
						   {
							
							//System.out.println(stringtoken + " " + "\n");
							//outputStream.write(stringtoken + " " + "\n");

						   }

						
					 }

					

					

						System.out.println(stringtoken + "\n");
						outputStream.write(stringtoken + "\n");
					
					 
				}

			}  
			  
			
			
		} finally {
			if (inputStream != null) {
				inputStream.close();
			}
			if (outputStream != null) {
				outputStream.close();
			}
		}
	}
}

i think we need to use linked lists can any one help me here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.