Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,402 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,402 people online right now. Registration is fast and FREE... Join Now!




Searching and Displaying Strings

 
Reply to this topicStart new topic

Searching and Displaying Strings, Searching a string/character from the user's input then it will di

xTEEN
26 Aug, 2008 - 06:14 PM
Post #1

New D.I.C Head
*

Joined: 30 Jul, 2008
Posts: 1

CODE

import java.io.*;

public class lab {
    public static void main(String args[]) throws IOException {
        
        java.io.BufferedReader in;
        String strInput , fndStr , tempCont="";
        char strCont;
        boolean fnd=false;
        
        BufferedReader key=new BufferedReader(new InputStreamReader(System.in));
        
        System.out.print("Enter String: ");
        strInput=key.readLine();
                
        System.out.print("Find: ");
        fndStr=key.readLine();
        
                for(int i=0;i<strInput.length();i++){
                    strCont=strInput.charAt(i);
                        tempCont=tempCont+strCont;
                        
                        if(fndStr==tempCont)
                        fnd=true;
                        System.out.print("["+fndStr+"]");
                        
                        if(fndStr!=tempCont)
                        System.out.print(strInput.charAt(i));
                    }
                
                    
        if(fnd)
            System.out.print("Match found!");
        else
            System.out.print("No match found!");
            
    }
}

User is offlineProfile CardPM
+Quote Post

pbl
RE: Searching And Displaying Strings
26 Aug, 2008 - 08:00 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,110



Thanked: 202 times
Dream Kudos: 75
My Contributions
And the question is ?
The program compiles ? (You should append error messages to your post)
The program generates error messages ? (You should append them to your post)
The program does not behave as you expected ? (What do you expect ?)
User is offlineProfile CardPM
+Quote Post

abgorn
RE: Searching And Displaying Strings
27 Aug, 2008 - 03:36 AM
Post #3

Hello Crap for Brains
Group Icon

Joined: 5 Jun, 2008
Posts: 881



Thanked: 5 times
Dream Kudos: 50
My Contributions
Ye, it would be helpful if you put a question before your code, because then we'd know exactly what's the problem and what your trying to do.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:31AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month