Home Answers Viewqa Java-Interview-Questions without using built-in functions

 
 


vasu
without using built-in functions
2 Answer(s)      7 months ago
Posted in : Java Interview Questions

Hai sir...

Please help me to solve this...

Findout occurances of each string in every another string (built - in functions are not at all allowed)

all, and, sand, falling wall and sand

View Answers

October 8, 2012 at 5:01 PM


Here is a java example that finds the occurrences of each string in every another string.

class  Occurrence
{
    public static void main(String[] args) 
    {
    String str = "all and sand falling wall and sand";
    String findStr = "and";
    int lastIndex = 0;
    int count = 0;

    while ((lastIndex = str.indexOf(findStr, lastIndex)) != -1) {
        count++;
        lastIndex += findStr.length() - 1;
    }

    System.out.println(findStr+" occurs " +count+ " times");

    }
}

October 8, 2012 at 5:02 PM


Here is another code.

import java.util.*;

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

        String[] st = {"all","and","sand","falling wall","and","sand"};
        HashMap<String, Integer> map = new HashMap<String, Integer>();
            String str="";
            for(int i=0;i<st.length;i++){
                str+=st[i]+" ";
            }
            str = str.toLowerCase(); 
                int count = -1;
                for (int i = 0; i < str.length(); i++) { 
                   if ((!Character.isLetter(str.charAt(i))) || (i + 1 == str.length())) { 
                            if (i - count > 1) { 
                            if (Character.isLetter(str.charAt(i))) 
                                i++;
                            String word = str.substring(count + 1, i);
                            if (map.containsKey(word)) { 
                            map.put(word, map.get(word) + 1);
                            }
                            else { 
                            map.put(word, 1);
                            } 
                        } 
                        count = i;
                    } 
                } 
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.addAll(map.values());
        Collections.sort(list, Collections.reverseOrder());
        int last = -1;
        for (Integer i : list) { 
            if (last == i) 
                continue;
            last = i;
            for (String s : map.keySet()) { 
                if (map.get(s) == i) 
                    System.out.println(s + ":" + i);
            } 
        } 
    } 
}









Related Pages:
without using built-in functions
without using built-in functions  Hai sir... Please help me to solve this... Findout occurances of each string in every another string (built - in functions are not at all allowed) all, and, sand, falling wall and sand
Java reverse string without using inbuilt functions
Java reverse string without using inbuilt functions In this tutorial, you will learn how to reverse string without using any inbuilt functions. Here, we have created a method to reverse the string and returns a new string with reverse
Add year to Date without using Calendar in java
Add year to Date without using Calendar in java  how could i add a year to a date function without using calendar functions
PHP Variables Functions
of PHP you should use PHP functions. There are more than 700 in-built functions... whenever we required in our application. Using functions in your application saving...PHP Variables Functions In this tutorial we learned about how to create
switch functions - Java Beginners
in the module. I need the alert to be written without trying to open internet... friend, This is running code, switch option using in javaSctipt
PHP Functions
3.11. Functions Function provides power to any programming language. It works... need. Moreover, PHP has its own built-in canned function library that can be used... to made your own functions?’ 3.11.1. Create a PHP Function A function
JDBC Functions
JDBC Functions       In this Tutorial we want to describe you a code that helps you easy to understand Jdbc Functions. The code include a class Jdbc Functions, Inside the main method, the list
Math Constants and Functions using JavaScript
Math Constants and Functions using JavaScript  What's Math Constants and Functions using JavaScript
associate functions with objects using JavaScript
associate functions with objects using JavaScript  How to associate functions with objects using JavaScript
using tiles without struts
using tiles without struts  Hi I am trying to make an application using tiles 2.0. Description of my web.xml is as follows: tiles org.apache.tiles.web.startup.TilesServlet
Functions and Methods
Functions and Methods  (1) Write a program in java to input 10... the frequency of each vowel. (5) Write a program in Java to input a string using... using switch case statement. import java.util.*; class FindDay { public
PHP Functions, PHP Functions Tutorials
; } Functions in PHP PHP provides many built-in functions to do the real job...PHP Functions In this section we will understand important PHP functions with the help of example code. What is Functions? Function is a block of code
Built in Data Format in Excel Using POI 3.0
Built in Data Format in Excel Using POI 3.0       In this program we are using the built... OLE 2 Compound Document format using Java .POI version 3.0 APIs provides
messages to the screen without using "document.write()"
messages to the screen without using "document.write()"  To write messages to the screen without using "document.write
Without Using Form in Java Script
Without Using Form in Java Script  HOw to Reset the data in javascript without using form tag
Struts Built-In Actions
Struts Built-In Actions    In this section we  will give a quick look to the  few of built-in utility actions shipped with Struts APIs. These built-in utility actions provide different
SQL Aggregate Functions
SQL Aggregate Functions       SQL Aggregate Functions is built in function that is used for the computation of records in a table. Understand with Example The Tutorial
without scanner
without scanner  a company need a system to store the data about the employees , the number of employees is dynamic , you need to store the following attributes : name , age , salary and note that we need to solve it using array
Pagination without using database in php
Pagination without using database in php  How can I show multiple images in multiple rows with pagination in php
Sorting arraylist without using Collection.sort()
Sorting arraylist without using Collection.sort()  Hi, How can I sort an arraylist without using Collection.sort() nad also I am not allowed to use any other data structure in the program? Is there any algorithm by using which I
Built In Properties
Built In Properties     ... using Ant. Ant provides access to all system properties as if they had been defined using a <property> task. Here is a list of the properties
Hibernate Built-in criterion "between" Date
Hibernate Built-in criterion "between" Date In this tutorial you will learn about how to use the built-in criterion ' between '... that provides the built-in criterion. Example : Here I am going to give
Hibernate's Built-in criterion: Between (using with Date)
Hibernate's Built-in criterion: Between (using with Date... to use "between" i.e.one of the built-in hibernate criterions. Restriction  class  provides built-in criterion via static factory methods. One
Draw graph using jsp without database connection
Draw graph using jsp without database connection  Draw graph using jsp code without database connection
greatest of 3 numbers using classes and functions.
greatest of 3 numbers using classes and functions.  WAP to calculate greatest of 3 numbers using classes and functions with parameters through input in main?   Java Find Largest Number import java.util.*; class
Hibernate Built-in criterion "between" Integer
Hibernate Built-in criterion "between" Integer In this tutorial you will learn about how to use the built-in criterion ' between '... is a factory class that provides the built-in criterion. Example : Here I am going
Struts 2 Validation (Int Validator)
; Struts 2 Framework provides in-built validation functions to validate user inputs. These validation functions are sufficient for any normal web application. In some cases these standard set of validation functions are not sufficient
Round of to a multiple of 5 without using function
Round of to a multiple of 5 without using function  Please help me out... U enter values like 239, 2543.876, 962.... Give me an equation without using any function which will give output of 240, 2545, 960 respectively
Round of to a multiple of 5 without using function
Round of to a multiple of 5 without using function  Please help me out... U enter values like 239, 2543.876, 962.... Give me an equation without using any function which will give output of 240, 2545, 960 respectively
Breaking a string into words without using StringTokenizer
Breaking a string into words without using StringTokenizer  how can we Break a string into words without using StringTokenizer ??   The given code convert the string into words. import java.util.*; class StringExample
Double To Int Without TypeCasting
Double To Int Without TypeCasting  How to convert Double to Int without using typecasting?   class ConvertDoubleToInt { public static void main(String[] args) { double d=25.5; int num=new
String length without using length() method in java
String length without using length() method in java  How to count length of string without using length() method in java?   Here is Example... the number of character into the given string without using the length() method
jsp functions - JSP-Servlet
jsp functions  hi,sir i need a simple jsp program using page directive with session attribute  Hi friend, To get the solution of your problem visit this link.... http://www.roseindia.net/jsp
DataGrid without DataBase
DataGrid without DataBase  I want display list of data without using... have to display the content of these elements but without having... will be in java file not in Database. Using JSP for frontend and java file
without ;
without ;  can u give me an example of a program without
without ;
without ;  can u give me an example of a program without
Program using String functions - Java Beginners
Program using String functions  Write a program to accept a sentence and find out how many times the word "the" occurs?  Hi Friend, Try the following code: import java.util.*; class CountSameWords
send without authentication mail using java - JavaMail
send without authentication mail using java  Dear All, I am tring to send simple mail without authentication using java. is it possible, could i send email without authentication. I have written following code. public
print reverse string without api
print reverse string without api  accept a string and print reverse without using api
Creating objects for classes and calling functions of a dll file using JNI
Creating objects for classes and calling functions of a dll file using JNI .... In this file, some c++ classes and functions are available. How can we create objects for these classes and how can we call these functions by using JNI. Am
jQuery Utility Functions
jQuery Utility Functions      In this section we are discussing about jQuery Utility Functions. Understanding these functions are important as you will have to use
Java repeat string without using loops
Java repeat string without using loops In this section, you will learn how to repeat string without using for loops. The given example accepts the number of times and iterates the string to the number of times set by the user without
Popup on hover without plug-in
Popup on hover without plug-in In this tutorial , we will discuss about using popup on hover without using plug-in. In this example , we have a logo/picture... of popup is set using css style sheet. popupwithoutplugin.html <html
creating own ArrayList without Collections?
creating own ArrayList without Collections?  How can we write our own arraylist without using collections in JAVA
Swap two numbers without using third variable
Swap two numbers without using third variable In this section we are going to swap two variables without using the third variable. For this, we have used... from the command prompt. Instead of using temporary variable, we have done some
retrive image from database using jsp without stream
retrive image from database using jsp without stream  How to retrive image from database using jsp without stream like (inputStream
how to delete a row in sql without using delete command.
how to delete a row in sql without using delete command.  how to delete a row in sql without using delete command. thanks in advance
how to validate the telephone number without using jquery in html with javascript
how to validate the telephone number without using jquery in html with javascript  how to validate the telephone number without using jquery in html with javascript
Retriving data from MYSQL without line break using java
Retriving data from MYSQL without line break using java  get data without line breaking from mysql table (i.e data stored as mediumtext )using java
Connect a linux machine from linux using java program without password
Connect a linux machine from linux using java program without password  Connect a linux machine from linux using java program without password. Can anyone help me

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.