Results 1 to 9 of 9

Thread: Runtime Error

  1. #1
    mathfxr is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default Runtime Error

    Hi there ,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
    Java 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
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by mathfxr View Post
    Hi there ,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
    This begs the question: what is the runtime error? Oh, b.t.w. your indentation style sucks much *yuck*

    kind regards,

    Jos

  3. #3
    mathfxr is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default a

    As i said before , it only said runtime error, but i did receive an email said that it might be my program didnt finish properly.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by mathfxr View Post
    As i said before , it only said runtime error
    Someone or something is hiding the real cause of the error from you then.

    kind regards,

    Jos

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    it might be my program didnt finish properly.
    Sounds bad. A program that doesn't finish properly should be sent out for repair.

    Can you get any more information than that?
    Can you add some comments to the code describing what it is supposed to do?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

  7. #7
    mathfxr is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    I already posted in UVA forum, but still no answer, i already spend two days for this thing. but still unable to solve it. so i got no ideas what is really going on with my code.as far as i know it perfectly run using my machine

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    Can you add some comments to the code describing what it is supposed to do?

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by mathfxr View Post
    I already posted in UVA forum
    That's still no reason to double post it here; and please post some information we can use to solve your problem. Dumping a piece of code here and add some arbitrary input later isn't going to help us to help you.

    kind regards,

    Jos

Similar Threads

  1. RunTime Error
    By LostinJavaLand in forum New To Java
    Replies: 3
    Last Post: 07-12-2010, 02:30 PM
  2. runtime error problems. please help!
    By RoadRunner in forum Forum Lobby
    Replies: 0
    Last Post: 04-21-2009, 06:03 PM
  3. I can't fix this runtime error in my program
    By Sinnergy in forum New To Java
    Replies: 5
    Last Post: 02-25-2009, 05:29 PM
  4. Replies: 3
    Last Post: 01-23-2009, 09:53 AM
  5. Weblogic 5.0 runtime error with EJB 1.0
    By somesh in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 08-25-2008, 04:09 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
  •