Results 1 to 1 of 1
- 04-16-2011, 06:53 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 1
- Rep Power
- 0
brackets insertion in a String table
Hi everybody,
I'm a beginner in java programing, and I've got a little problem. I'm trying to write a little program which got as input a string as food(chocolate(good)),(caramel(youmi)). And I want to get as output a string as food((chocolate([good])),(caramel([youmi]))) i.e. insert an opening bracket [ after the last open parenthesis and a closing bracket before the first closing parenthesis each substring before the comma. My code, but i't gives me the error
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at me.Main.main(Main.java:29)
But I can't find how to fix it can anyone help me please....
Thank you,
Here is my code
Java Code:public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here String input= "batata(zrodiya(macaroun))"; String[] sentences = input.split(","); for (int i = 0; i < sentences.length; i++) { int l=0; char[] sentenceTab = sentences[i].toCharArray(); int leng=sentences.length+4; char[] sentenceTab1 = sentences[leng].toCharArray(); char c1=' '; int k; for(k =0; k < sentenceTab.length ; k++){ for (l=0; l<sentenceTab1.length; l++) { sentenceTab1[l]=sentenceTab[k]; }} for (l=0; l<sentenceTab1.length+2; l++) { c1=sentenceTab[l]; if (c1==')'){ int v = l ; for (l=sentenceTab1.length+2; l>0; l--) { sentenceTab1[l]=sentenceTab1[l-1]; } sentenceTab1[v]=']'; } } for (l=sentenceTab1.length+2; l>0; l--) {char c = sentenceTab[l-1]; if (c== '('){ int j=c; for (int v=sentenceTab1.length+2; v>0; v--) { sentenceTab1[v]=sentenceTab1[v-1]; } sentenceTab1[j+1]='['; } } sentences[i] = String.copyValueOf(sentenceTab1); } input = ""; for (int i = 0; i < sentences.length-1; i++) { input += sentences[i]+","; } input+=sentences[sentences.length-1]; System.out.println(input); } }
Similar Threads
-
Java method that check brackets in String are matched?
By neonz in forum New To JavaReplies: 21Last Post: 03-02-2011, 03:34 PM -
How to index a table with an ID with the type String
By crishantha in forum LuceneReplies: 0Last Post: 12-03-2010, 06:07 AM -
use of <> brackets
By dqlevitt in forum New To JavaReplies: 3Last Post: 05-27-2010, 09:34 PM -
how to at strings to a string like a table
By petrosgraf in forum New To JavaReplies: 14Last Post: 09-24-2009, 12:00 AM -
How to change Bubble+Selection+Insertion Sorts to Sort String Values?
By VinceGuad in forum New To JavaReplies: 3Last Post: 01-26-2009, 12:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks