0

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

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by BestJewSinceJC
0
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.