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 2 of 2

Thread: Runtime Error running in UVA

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Runtime Error running in UVA

    Hi all ,im new with java, i write a code which working fine in my machine but when i submit to UVA web it produce runtime error,could anyone help me identify what is the cause of that problem
    .It does not show any specific error for me to look into, it just say that my program didnt finish properly.
    here is my code
    import java.util.*;
    import java.util.Arrays;
     
     
    class BruteForces {
     
        public static int totalsum=0;
        public static String outputAll1="";
        public static String outputAll2="";
     
        public static void main(String[] args) {
     
     
     
            //iniatialize array;
     
     
            Scanner in = new Scanner(System.in);//use system.in to read input
     
     
            int Intdatacase=0;
            String datacase="";
            //get data case
           try { datacase = in.next();
            Intdatacase=Integer.parseInt(datacase);
            } catch ( Exception e) { System.exit(0); }
            if ( datacase == null ) System.exit(0);
     
            int intLoop=0,IntInputsz=0;
            String InputDatas="";
            if(Intdatacase>15||Intdatacase<1)System.exit(0);
            for(intLoop=0;intLoop<Intdatacase;intLoop++){
              outputAll1="";
              outputAll2="";
              String[] InputDatasLoopAr1;
              String[] InputDatasLoopAr2;
              String InputDatasLoopA="",InputDatasLoopA2="";
              //get input for each case
               InputDatas="";
     
     
     
              //get how many words in a cases
                    try { IntInputsz = in.nextInt();
     
                            } catch ( Exception e) { break; }
     
                    //enter first words
                    if(IntInputsz>0&&IntInputsz<=100){
     
                    try{
     
                     InputDatas = in.next();
                                     InputDatas=InputDatas.toLowerCase().trim();
                                     if(InputDatas.length()>100)break;
                       } catch ( Exception e) { break; }
                        if ( InputDatas == null ) break;
                    }
                    else break;
                    for(int i=0;i<IntInputsz-1;i++)
                    {
     
                                String InputDatasLoop="";
                                //get next word if size word >1
                                try { InputDatasLoop = in.next();
                                        InputDatasLoop=InputDatasLoop.toLowerCase().trim();
                                        if(InputDatasLoop.length()>100)break;
                                } catch ( Exception e) {
     
                                    break; }
                                if ( InputDatasLoop == null ) {break;}
     
                        if(InputDatasLoop.charAt(0)==InputDatas.charAt(0))
                                    {
                                        InputDatasLoopA=InputDatasLoopA+InputDatasLoop.toLowerCase()+" ";
                                    }
                        else
                                    InputDatasLoopA2=InputDatasLoopA2+InputDatasLoop.toLowerCase()+" ";
     
                    }
     
                InputDatasLoopAr1=InputDatasLoopA.split(" ");
                InputDatasLoopAr2=InputDatasLoopA2.split(" ");
     
                Arrays.sort(InputDatasLoopAr1);
                    Arrays.sort(InputDatasLoopAr2);
     
                    totalsum=InputDatas.length();//get first value of word
                    outputAll1=InputDatas;//insert first word
                    if(InputDatasLoopA.length()>1)
                    calculate(InputDatasLoopAr1,InputDatas,"A",totalsum);//calculate for first array
                    InputDatas="";//clear inputdatas
                       if(InputDatasLoopA2.length()>1)
                    calculate(InputDatasLoopAr2,InputDatas,"D",totalsum);//calculate for second array
     
                    System.out.printf(totalsum+"\n"+outputAll1+"\n"+outputAll2);//display output
     
            //intLoop++;
     
            }
     
     
            System.exit(0);
        }
     
    public static void calculate(String[] strArray,String InputDatas,String Arrange,int total)
    {               int LastIndex=InputDatas.length(),CountNext=0;
                   int InputDatasB=0,Loops=0;
     
          for(int iz=0;iz<strArray.length;)
            {
     
     
              if((InputDatasB==1&&!strArray[iz].equals("-"))||(InputDatas.equals("")&&!strArray[iz].equals("-")))
              {
                 InputDatas=strArray[iz];
                 LastIndex=strArray[iz].length();
                 InputDatasB=0;
                 totalsum+=LastIndex;
     
              }
              if(!strArray[iz].equals("-")){
     
                int pos2 = strArray[iz].indexOf(InputDatas.substring(0, LastIndex));
                if(pos2==0)
                {
                        if(Arrange.equals("D"))
                        outputAll2=strArray[iz]+"\n"+outputAll2;
                        else
                        outputAll1=outputAll1+"\n"+strArray[iz];
     
                        totalsum+=(strArray[iz].length()-LastIndex);
     
                        InputDatas=strArray[iz];
                        LastIndex=strArray[iz].length();
                        strArray[iz]="-";
                        Arrays.sort(strArray);
                }
              }
                iz++;
                   //    CountNext=iz+1;
                    if(iz==strArray.length)
                    {
     
                     iz=0;
                     LastIndex--;
     
                    }
     
                    if(LastIndex==0)
                    {
                       InputDatasB=1;
     
                    }
                    if(strArray[strArray.length-1].equals("-")){
                      //          Loops=1;
                        break;
                    }
     
     
              }
            return;
     
    }
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Runtime Error running in UVA

    Cross posted at Runtime Error - Java Forums

Similar Threads

  1. Is it possible to load classes at runtime that are discovered from a directory
    By mydarkpassenger in forum Java Theory & Questions
    Replies: 11
    Last Post: June 10th, 2010, 10:33 AM
  2. Create buttons at runtime
    By rtumatt in forum AWT / Java Swing
    Replies: 2
    Last Post: May 24th, 2010, 06:42 AM
  3. How to Navigate to a URL with Runtime.getRuntime().exec()
    By Flash in forum Java SE API Tutorials
    Replies: 4
    Last Post: October 5th, 2009, 07:18 PM
  4. Getting Null Pointer Exception in runtime
    By RoadRunner in forum Exceptions
    Replies: 1
    Last Post: April 26th, 2009, 01:21 PM
  5. Replies: 1
    Last Post: March 3rd, 2009, 08:04 AM