int i = 1;
int sum = 0;
do {
    sum += i;
    i = (2 * i) % 3;
} while (i != 1); 
System.out.println(sum);