added loop with inner for Java