Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By SurfMan

Thread: clear my bug ?

  1. #1
    Adithya is offline Member
    Join Date
    Jun 2014
    Posts
    24
    Rep Power
    0

    Default clear my bug ?

    i have written the code to read the line from file and save first string as word and and remaining string as meaning..
    eg: innovation a new method, idea, product, etc.
    word = innovation
    meaning = a new method, idea, product, etc.

    in my code there is no error and have a mistake what it is means first assigning word is ok and while saving meaning ..it saves like{
    a a new a new method } like that


    Java Code:
    import java.io.BufferedReader;
    import java.io.FileReader;
    
     
    
    public class Dil{
    	
    	public static void main(String[] arg)throws Exception
    	{
    		
    		BufferedReader in;
    		
    		
    		try{
    		in = new BufferedReader(new FileReader("dili.txt"));
    
    			String ln;			
    			int j=0;
    			
    			String[] m= new String[5];
    		
    			do{
    			ln =  in.readLine();
    				if( ln != null)
    				{ 
    					
     					String word[] =ln.split(" ");
    		
     					String t = " ";
    				    System.out.println(word[0]);
    					for(int i=1; i<word.length; i++)
    					
    					 t+= t + word[i]+" ";	
    					 
    				    m[j]+= t;
    					System.out.println(m[j]);
         				j++;
     				}				
    		
    			}while( ln != null );		
    			
    		}catch(Exception e){
    			System.out.println(e);	
    		}
    	}
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default Re: clear my bug ?

    Can you post the program's output and add some comments saying what is wrong and show what it should be.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    ami64 is offline Member
    Join Date
    Jun 2014
    Posts
    12
    Rep Power
    0

    Default Re: clear my bug ?

    I comment mistaken parts and correct it on the next line.

    Java Code:
    public class Dil{
         
        public static void main(String[] arg)throws Exception
        {
             
            BufferedReader in;
             
             
            try{
            in = new BufferedReader(new FileReader("dili.txt"));
     
                String ln;          
                int j=0;
                 
                String[] m= new String[5];
             
                do{
                ln =  in.readLine();
                    if( ln != null)
                    { 
                         
                        String word[] =ln.split(" ");
             
                      //  String t = " ";
                        String t = "";
                        System.out.println(word[0]);
                        for(int i=1; i<word.length; i++)
                         
                       //  t+= t + word[i]+" ";  
                        t+=  word[i]+" ";  
                          
                       // m[j]+= t;
                        m[j]= t;
                        System.out.println(m[j]);
                        j++;
                    }               
             
                }while( ln != null );       
                 
            }catch(Exception e){
                System.out.println(e);  
            }
        }
    }
    Last edited by ami64; 07-07-2014 at 09:14 AM.

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default Re: clear my bug ?

    without comments ,your code is very confusing..u are having various effective ways of doing this...but without deviating from your code flow i will help you.
    change this do part
    do{
    ln = in.readLine();
    if( ln != null)
    {

    String word[] =ln.split(" ");//split here
    for(int i = 1 ; i < word.length ; i++)
    {
    meaning = meaning+ word[i]; //leave the first element of the array and concat rest for the meaning part

    }
    System.out.println(word[0]+"="+meaning);
    meaning="";
    }

    }while( ln != null );
    Ramya:cool:

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,087
    Rep Power
    4

    Default Re: clear my bug ?

    Quote Originally Posted by RamyaSivakanth View Post
    without comments ,your code is very confusing..u are having various effective ways of doing this...but without deviating from your code flow i will help you.
    change this do part
    Please use [code][/code] tags to display code. I have asked you this numerous times. It makes it readable for all of us. Please.
    RamyaSivakanth likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. i-net Clear Reports 13.0.189
    By java software in forum Java Software
    Replies: 0
    Last Post: 06-23-2013, 11:41 PM
  2. Best Way to Clear a BufferedImage?
    By Prime624 in forum New To Java
    Replies: 3
    Last Post: 05-18-2013, 07:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •