I'm am currently attending college and taking a java programming class. I am somewhat stumped. I get thrown in a situation and need to figure out the answer, now I do have some programming experience and in this case, my thinking would be to use a iterator. I do not want an answer, just a some advice in the right direction.

public class ContinueTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        for(int count =1; count <= 10; count ++)
        {
           if(count == 5)
              continue; //skip remaining code

           System.out.printf("%d", count);
        }
      System.out.println("\nUsed  continue to skip printing 5");
    }

}

Now ultimately, I was thinking of using a iterator and use iter.remove() and remove the 5. The object is to redo this code without using a continue. There has to be another way of going about it besides using a iterator.

-Democles

public class ContinueTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        for(int count =1; count <= 10; count ++)
        {
           if(count != 5)
              System.out.printf("%d", count);
        }
      System.out.println("\nUsed  continue to skip printing 5");
    }

}

..

You can also use System.out.print(count); rather than using printf.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.