java programming




Comment hidden because of low score. Click to expand.
1
of 1 vote

import java.util.ArrayList;
import java.util.List;

public class FindWordInString {

	/*
	assume that dictionary has only 5 words...
	APPLE,APE,BABY,BALL,CAT
write a program which will accept a string and list all possible words in the dictionary which start with that string.use binary trees for fast retrieval.
	 */
	public static void main(String[] args) {
		
		//Letus take here ArrayList is a Dictionary		
		List<String> fruits=new ArrayList<String>();
		
		//This ArrayList for storing the matching words
		List<String> match_words=new ArrayList<String>();
		
		fruits.add("APPLE");
		fruits.add("APE");
		fruits.add("BYBA");
		fruits.add("BALL");
		fruits.add("CAT");
		
		//Here i will take one string which will search in List		
		String search="BA";
		
		
		
		for(String s:fruits)
		{
			if(s.indexOf(search) >= 0)
				match_words.add(s);
		}
		
		
		
		System.out.println("Matched words are:"+match_words);

	}

}

- sunil s June 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;

public class MatchString {

	public static void main(String[] args) {
		String[] dictionary = new String[]{"APPLE","APE","BABY","BALL","CAT"};
		ArrayList<String> matchWords = new ArrayList<String>();
		for(int i=0; i < dictionary.length; i++){
			if(dictionary[i].indexOf(args[0]) > -1) {
				matchWords.add(dictionary[i]);
		}
	}
	System.out.println("Matching Strings are "+matchWords.toString());
		
		
		}

	}

- Sandeep Khanna September 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(string args[ ]){
int i=0;
int ans;
System.out.println("give ans");
}

- java March 09, 2015 | Flag Reply




Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More