-4

I need to apply a continue statement that will skip printing the first 10 values.

I already have my code

public class numbers {

    public static void main(String[] args) {

         for (int number=1; number <= 99; number++){

             if (number % 2 == 0)
                 System.out.print(number + " " );

                        System.out.println();
             }
         }
    }
Lovias
  • 7
  • 2
  • Then do some research on "if" and "continue", instead of dumping something that could also be just the template you got as starter for your homework. Hint: you *learn* programming by actively trying. – GhostCat Aug 15 '17 at 07:04

2 Answers2

1

Just have another counter

    int count = 0;
    for (int number=1; number <= 50; number++){

        if (number % 2 == 0 && count++ >= 10)
        {
            System.out.print(number + " " );
            System.out.println();
        }
   }

or if you want to use a continue

    int count = 0;
    for (int number=1; number <= 50; number++){

        if (number % 2 == 0)
        {
            if (count++ < 10)
                   continue;

            System.out.print(number + " " );
            System.out.println();
        }
   }
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
0

Add a counter:

public static void main(String[] args) {
     int counter = 0;
     for (int number = 1; number <= 50; number++) {
         if (number % 2 == 0) {
             counter++;
             if (counter <= 10) {
                 continue;
             }
             System.out.println(number + " " );
         }
     }
}

With Java 8 Streams it can be written more elegantly:

IntStream.rangeClosed(1,50).filter(i -> i % 2 == 0).skip(10).forEach(System.out::println);
Eran
  • 387,369
  • 54
  • 702
  • 768
  • He is a newbie who asks to use *continue* because his assignment tells him to do so. Your answer doesn't address that all. And throwing a stream at a person unable to write down "continue" ... seriously? – GhostCat Aug 15 '17 at 07:05
  • Well, what I read said *I need to apply a continue statement*. – GhostCat Aug 15 '17 at 07:08