Answer to Question #14870 in Java | JSP | JSF for Kaze

Question #14870
Write a program that, starting from value 1, outputs the first 20 positive integers that are divisible by 2, but are not divisible by 3
1
Expert's answer
2012-09-14T10:08:54-0400

public class PositiveInteger {

/**
& * @param args
& */
public static void main(String[] args) {
& // TODO Auto-generated method stub
& int count = 0;
& int num = 1;
& while (count < 20) {
& if (num % 2 == 0 && num % 3 != 0) {
& System.out.println(num);
& count++;
& }
& num++;
& }
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS