2016-09-29 6 views
0
1 condition: 

    String str = "2d5"; 
    String[] temp; 
    String delimiter = "d"; 
    temp = str.split(delimiter); 
    String a=temp[0]; 
    String b=temp[1]; 
    Integer q,w,e; 
    q=Integer.parseInt(a); 
    w=Integer.parseInt(b); 
    e=q*w; 
    for(int i =q; i <=e ; i++){ //values will be (2,3.4,5,6,7,8,9,10) 
    data.add(new Card(i));} //data is an arraylist and Card is a class, here values will be stored in an arraylist) 

     2nd Condition: 

     str = ""2d5-2; 
     delimiter = "d|\\-"; 
     temp = str.split(delimiter); 
     String a=temp[0]; 
     String b=temp[1]; 
     String c=temp[2]; 
     q=Integer.parseInt(a); 
     w=Integer.parseInt(b); 
     r=Integer.parseInt(c); 
     for(int i =0; i < r ; i++){ 
     data1.add(data.get(0)); // data1 is another arraylist 
     data.remove(0); // values will be removed from arraylist stating from index 0 i.e (4,5,6,7,8,9,10) 

     } 

は、ここで私が実際にやってみたかった私は、「D」区切り文字で文字列を分割するたびに、私はで文字列を分割するとき、私はまた、実行するための第一条件を望んでいたということです「 - 」私は第二の条件が同じで実行したかった区切り文字クラス。区切り文字で区切られたループの条件を設定するにはどうすればよいですか?

+1

次の2つの条件を必要とする理由あなたのループ条件については、その後全く違う??はっきり言って何が必要なのか/最終的なo/p? –

答えて

0
if (delimiter.equals("d")) { 
     //delimiter is 'd'. So carry out 1st condition action. 
    } else if (delimiter.equals("-")) { 
     //delimiter is '-'. So carry out 2nd condition action. 
    } 
1

あなたが何かを求めている:

String [] temp = str.split("-"); 
if (temp.length == 1) // That is, "2d5" format 
{ 
    delimiter = "d"; 
    temp = str.split(delimiter); 
    doCondition1(...); 
} 
else 
{ 
    delimiter = "d|\\-"; 
    temp = str.split(delimiter); 
    doCondition2(); 
} 
関連する問題