Results 1 to 11 of 11
Thread: Runtime Error running in UVA
- 09-17-2010, 07:51 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
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.
i had change the code too many times but still runtime error.
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; } }
- 09-17-2010, 08:08 PM #2
Have you run the program in a command prompt window successfully?
What is the program supposed to do? Can you execute the program and copy and paste here the console from when you run it?
- 09-17-2010, 08:15 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
This is based on uva problem number 10602 editor nottoobad.
Yerp i succesfully enter some test data, but when submit it to uva it said runtime error which i dont have any clue, i try to change the code to many times but the same result.
Sample Input
3
3
this
thin
thing
4
popcorn
apple
apricote
plum
2
hello
hello
output
6
this
thin
thing
21
popcorn
plum
apricote
apple
5
hello
hello
- 09-17-2010, 08:18 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 09-17-2010, 08:21 PM #5
What happens when YOU execute the program?
Copy the full console and paste it here. If you are on Windows:
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
- 09-17-2010, 08:29 PM #6
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
U can know about uva by visit this url
uva.onlinejudge.org
here the content that i enter to the console
D:\java>javac BruteForces.java
D:\java>java BruteForces
3
3
this
thing
thin
6
this
thin
thing
4
popcorn
apple
apricote
plum
21
popcorn
plum
apricote
apple
2
hello
hello
5
hello
hello
D:\java>
- 09-17-2010, 08:33 PM #7
If you don't get an error, why would I get an error with the same input as you are using?
There is nothing to work on with out an error or some info from whoever is telling you your code has a problem. Get them to explain in more detail.
- 09-17-2010, 09:02 PM #8
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
What kind of error do you get?it is weird if u got errors and im not.could you let me know what is the errors did u get? Did you use any special option for compiling or running?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 the 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);//check datacase condition for(intLoop=0;intLoop<Intdatacase;intLoop++){//loop depend on datacase outputAll1=""; outputAll2=""; String[] InputDatasLoopAr1; String[] InputDatasLoopAr2; String InputDatasLoopA="",InputDatasLoopA2=""; //get input for each case InputDatas=""; //get how many numbers of words line in a cases try { IntInputsz = in.nextInt(); } catch ( Exception e) { break; } if(IntInputsz>0&&IntInputsz<=100){//check condition of words enter //get the first words try{ InputDatas = in.next(); InputDatas=InputDatas.toLowerCase().trim(); if(InputDatas.length()>100)break; } catch ( Exception e) { break; } if ( InputDatas == null ) break; } else break; //if the number of words line >1 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))//check whether input at index 0 equal with InputDatas to group it { InputDatasLoopA=InputDatasLoopA+InputDatasLoop.toLowerCase()+" ";//add data into string } else//if not equal put it in second string InputDatasLoopA2=InputDatasLoopA2+InputDatasLoop.toLowerCase()+" ";//add data } InputDatasLoopAr1=InputDatasLoopA.split(" ");//split the string into first array InputDatasLoopAr2=InputDatasLoopA2.split(" ");//split the string into second array Arrays.sort(InputDatasLoopAr2);//sort the second array totalsum=InputDatas.length();//get first value of word let say word hello contain 5 char so totalsum become 5 outputAll1=InputDatas;//insert first word for output if(InputDatasLoopA.length()>1)//if 1st array not empty run calculate function to calculate word char in the array { Arrays.sort(InputDatasLoopAr1);//sort the first array calculate(InputDatasLoopAr1,InputDatas,"A",totalsum);//calculate for first array } InputDatas="";//clear inputdatas if(InputDatasLoopA2.length()>1)//if 2nd array not empty run calculate function to calculate word char in the array { Arrays.sort(InputDatasLoopAr2);//sort the second array 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 the last index of char =0 or inputdatas is empty retrieve new value if((InputDatasB==1&&!strArray[iz].equals("-"))||(InputDatas.equals("")&&!strArray[iz].equals("-"))) { InputDatas=strArray[iz];//get new data for InputDatas LastIndex=strArray[iz].length();//Get Last index InputDatasB=0;//reset InputDatasB to 0 totalsum+=LastIndex;//sum the the new number character } if(!strArray[iz].equals("-")){//run if string not equal "-" int pos2 = strArray[iz].indexOf(InputDatas.substring(0, LastIndex));//compare strArray with inputdatas if(pos2==0)//check whether strArray[iz] contain InputDatas substring from 0 to LastIndex { //arrangement of output if(Arrange.equals("D")) outputAll2=strArray[iz]+"\n"+outputAll2; else outputAll1=outputAll1+"\n"+strArray[iz]; totalsum+=(strArray[iz].length()-LastIndex);//calculate the number of char which not equal with InputDatas ex. InputDatas=strArray[iz];//replace InputDatas with new value LastIndex=strArray[iz].length();//get the Last Index number for new data strArray[iz]="-";//set the array to - after calculate Arrays.sort(strArray);//sort back the array since it contain "-" } } iz++; // CountNext=iz+1; if(iz==strArray.length)//if still have word in the array but loop is reach limit reset the loop { iz=0;//reset loop LastIndex--;//reduce the index to find similar characters } if(LastIndex==0)//check if the Lastindex=0 this mean that there are no matching character { InputDatasB=1;//Set InputDatasB to 1 to retrieve new inputdatas in next loop } if(strArray[strArray.length-1].equals("-")){ // Loops=1; break;//break loop if the last index equal "-"; } } return; } }
Thanks for helping me out.
- 09-17-2010, 09:46 PM #9
I didn't get any errors.
I changed your program by hardcoding the responses to the Scanner vs running the program in a command prompt window.
Can you change the program to be completely selfcontained, ie NOT to require any user input and see what happens with the program that way.
For example add this class with the correct input supplied to your test program:
Modify your code by commenting out the Scanner usage and adding a new statement:Java Code:// Inline replacement class for Scanner static class GetInput { int intIdx = 0; // index to theStrings int strIdx = 0; // index to theInts // The data to be returned: final String[] theStrings = {"3", "this", "thing", "thin"}; final int[] theInts = {3, 4}; // Methods to return the data String next() { System.out.println(theStrings[strIdx]); // show what was read return theStrings[strIdx++]; } int nextInt() { System.out.println(theInts[intIdx]); // show what was read return theInts[intIdx++]; } } // end class GetInput
Java Code:// Scanner in = new Scanner(System.in);//use system.in to read input GetInput in = new GetInput();Last edited by Norm; 09-18-2010 at 01:52 AM.
- 09-18-2010, 01:29 AM #10
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
Do you want me to used the class that u provided or alter it by my self?
i alter it based on my understanding
this is the coding
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=1; String datacase=""; //get the data case // try { datacase = in.next(); // Intdatacase=Integer.parseInt(datacase); // } catch ( Exception e) { System.exit(0); } // if ( datacase == null ) System.exit(0); int intLoop,IntInputsz=0; if(Intdatacase>15||Intdatacase<1)System.exit(0);//check datacase condition for(intLoop=0;intLoop<Intdatacase;intLoop++){//loop depend on datacase outputAll1=""; outputAll2=""; String[] InputDatasLoopAr1; String[] InputDatasLoopAr2; String InputDatasLoopA="",InputDatasLoopA2=""; String[] InputDatas={"this","thin","thing","gayus"}; //get input for each case // InputDatas=""; IntInputsz=4;//new //get how many numbers of words line in a cases // try { IntInputsz = in.nextInt(); // // } catch ( Exception e) { break; } // // // if(IntInputsz>0&&IntInputsz<=100){//check condition of words enter // //get the first words // try{ // // InputDatas = in.next(); // InputDatas=InputDatas.toLowerCase().trim(); // if(InputDatas.length()>100)break; // } catch ( Exception e) { break; } // if ( InputDatas == null ) break; // } // else break; //if the number of words line >1 for(int i=1;i<IntInputsz;i++) { String InputDatasLoop=InputDatas[i]; //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[0].charAt(0))//check whether input at index 0 equal with InputDatas to group it { InputDatasLoopA=InputDatasLoopA+InputDatasLoop.toLowerCase()+" ";//add data into string } else//if not equal put it in second string InputDatasLoopA2=InputDatasLoopA2+InputDatasLoop.toLowerCase()+" ";//add data } InputDatasLoopAr1=InputDatasLoopA.split(" ");//split the string into first array InputDatasLoopAr2=InputDatasLoopA2.split(" ");//split the string into second array totalsum=InputDatas[0].length();//get first value of word let say word hello contain 5 char so totalsum become 5 outputAll1=InputDatas[0];//insert first word for output if(InputDatasLoopA.length()>1)//if 1st array not empty run calculate function to calculate word char in the array { Arrays.sort(InputDatasLoopAr1);//sort the first array calculate(InputDatasLoopAr1,InputDatas[0],"A",totalsum);//calculate for first array } InputDatas[0]="";//clear inputdatas if(InputDatasLoopA2.length()>1)//if 2nd array not empty run calculate function to calculate word char in the array { Arrays.sort(InputDatasLoopAr2);//sort the second array calculate(InputDatasLoopAr2,InputDatas[0],"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 the last index of char =0 or inputdatas is empty retrieve new value if((InputDatasB==1&&!strArray[iz].equals("-"))||(InputDatas.equals("")&&!strArray[iz].equals("-"))) { InputDatas=strArray[iz];//get new data for InputDatas LastIndex=strArray[iz].length();//Get Last index InputDatasB=0;//reset InputDatasB to 0 totalsum+=LastIndex;//sum the the new number character } if(!strArray[iz].equals("-")){//run if string not equal "-" int pos2 = strArray[iz].indexOf(InputDatas.substring(0, LastIndex));//compare strArray with inputdatas if(pos2==0)//check whether strArray[iz] contain InputDatas substring from 0 to LastIndex { //arrangement of output if(Arrange.equals("D")) outputAll2=strArray[iz]+"\n"+outputAll2; else outputAll1=outputAll1+"\n"+strArray[iz]; totalsum+=(strArray[iz].length()-LastIndex);//calculate the number of char which not equal with InputDatas ex. InputDatas=strArray[iz];//replace InputDatas with new value LastIndex=strArray[iz].length();//get the Last Index number for new data strArray[iz]="-";//set the array to - after calculate Arrays.sort(strArray);//sort back the array since it contain "-" } } iz++; // CountNext=iz+1; if(iz==strArray.length)//if still have word in the array but loop is reach limit reset the loop { iz=0;//reset loop LastIndex--;//reduce the index to find similar characters } if(LastIndex==0)//check if the Lastindex=0 this mean that there are no matching character { InputDatasB=1;//Set InputDatasB to 1 to retrieve new inputdatas in next loop } if(strArray[strArray.length-1].equals("-")){ // Loops=1; break;//break loop if the last index equal "-"; } } return; } }
- 09-18-2010, 01:50 AM #11
Similar Threads
-
problem with Runtime.getRuntime().exec when running java in .bat
By Shayko in forum Threads and SynchronizationReplies: 2Last Post: 01-27-2010, 07:46 PM -
Running system comman with special symbols using Runtime.exec()
By sda in forum New To JavaReplies: 0Last Post: 07-13-2009, 05:22 PM -
java runtime isn't running
By v1nsai in forum New To JavaReplies: 3Last Post: 03-31-2009, 07:33 PM -
Diference Between compiler error Garbage collection and Runtime Error?
By makpandian in forum New To JavaReplies: 3Last Post: 01-23-2009, 08:53 AM -
Compiling and running code in runtime
By tim in forum New To JavaReplies: 4Last Post: 01-27-2008, 06:58 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks