jeudi 29 octobre 2015

Using if else in For Loop increment

I have a problem in Java:

Given a string, return a string made of the chars at indexes 0,1,4,5,8,9...

I know how to solve it, however I was wondering if it's possible for me to use if-else in for-loop increment itself, for example:

for (int i=0; i < str.length(); if (i%4==0) i++, else i+=3){
    result += str.charAt(i);
}

Can we do something like that?

Aucun commentaire:

Enregistrer un commentaire