Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Problem in the loops

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem in the loops

    here is the oprogram for reading entries fro a file and making all possible combinations for the entries of those files each file contains 20,000
    entries the first while loop runs for all 20,000 entries but the inner runs foor only one entry

    package combinator;

    import java.io.*;

    import Reader.HandsFileReader;

    public class FinalCombination{

    HandsFileReader hfr=new HandsFileReader();
    BufferedReader b1,b2,s;
    String bs1,bs2, ss;
    final String separator =System.getProperty("line.separator");
    public void finalRead(){
    try{
    FileWriter fr=new FileWriter("F:/java/Project/outputfiles/FinalCombination.txt");

    b1=hfr.readSingle();
    b2=hfr.readSingle();
    s=hfr.readSamyukta();

    while((bs2=b1.readLine())!=null){
    while((bs1=b2.readLine())!=null){
    String temp=(bs1+","+bs2);
    char []c=temp.toCharArray();
    for(int i=0;i<c.length;i++){
    fr.append(c[i]);
    }
    fr.append(separator);
    }
    while((ss=s.readLine())!=null){
    String temp=(ss+","+ss);
    char []c=temp.toCharArray();
    for(int i=0;i<c.length;i++){
    fr.append(c[i]);
    }
    fr.append(separator);

    }
    fr.close();

    }
    }
    catch(IOException e){
    e.printStackTrace();
    }
    System.out.println("Done");
    }
    public static void main(String[] args) {
    FinalCombination fc=new FinalCombination();
    fc.finalRead();
    }
    }


    The Underlined second loop is executing only once while thw outer loop executes untill the end of the file
    here is the sample of the input file


    an,0,0,0,0,0,0
    swa,0,0,0,0,0,0
    dol,0,0,0,0,0,0
    pus,0,0,0,0,0,0
    katv,0,0,0,0,0,0
    an,0,0,0,0,90,0
    swa,0,0,0,0,90,0
    dol,0,0,0,0,90,0
    pus,0,0,0,0,90,0
    katv,0,0,0,0,90,0
    an,0,0,0,0,180,0
    swa,0,0,0,0,180,0
    dol,0,0,0,0,180,0
    pus,0,0,0,0,180,0
    katv,0,0,0,0,180,0
    an,0,0,0,90,0,0
    swa,0,0,0,90,0,0

    total 20,000 input both the file and i want their all possible combinations



    and the output i want is like this all possible combination of two files with 20,000 string entries
    an,0,0,0,0,0,0swa,0,0,0,0,0,0
    dol,0,0,0,0,0,0pus,0,0,0,0,0,0
    katv,0,0,0,0,0,0an,0,0,0,0,90,0
    swa,0,0,0,0,90,0dol,0,0,0,0,90,0
    pus,0,0,0,0,90,0katv,0,0,0,0,90,0
    an,0,0,0,0,180,0swa,0,0,0,0,180,0
    dol,0,0,0,0,180,0pus,0,0,0,0,180,0
    katv,0,0,0,0,180,0an,0,0,0,90,0,0

    please suggest if dere is any other possible way to get such a huge combination


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,512
    My Mood
    Grumpy
    Thanks
    0
    Thanked 165 Times in 156 Posts

    Default Re: Problem in the loops

    FILE READER PROGRAM

    Duplicate post.

    Please do not start another thread. You are already getting help in the above thread. Why not continuing asking for help there?
    Improving the world one idiot at a time!

  3. The Following User Says Thank You to Junky For This Useful Post:

    JavaPF (July 22nd, 2011)

  4. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Problem in the loops

    Thread closed.

    See original thread - FILE READER PROGRAM
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. [SOLVED] I am a java newb and I am having a problem with my while loops.
    By Deaththekid in forum Loops & Control Statements
    Replies: 22
    Last Post: July 10th, 2011, 07:26 AM
  2. help with loops
    By kidza12 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 26th, 2011, 11:42 PM
  3. help with loops... :(
    By Macgrubber in forum Loops & Control Statements
    Replies: 2
    Last Post: November 2nd, 2010, 12:38 PM
  4. need help with loops plz
    By Kilowog in forum Loops & Control Statements
    Replies: 4
    Last Post: September 28th, 2009, 08:11 AM
  5. Replies: 11
    Last Post: April 29th, 2009, 03:12 AM

Tags for this Thread