Answer to Question #349922 in Java | JSP | JSF for Yadhu

Question #349922

Write a program to print all the composite numbers between a and b

1
Expert's answer
2022-06-13T08:27:30-0400
public class CompositeNumber {
    public static Boolean isComposite(int n) {
        if (n < 4) return false;
        for (int i = 2; i < n; i++) {
           if (n % i == 0) return true;
        }
        return false;     
    }
    public static void main(String[] args) {
        int a = Integer.parseInt(args[0]);
        int b = Integer.parseInt(args[1]);
        for (int i = a; i <= b; i++) {
            if (isComposite(i)) System.out.print(i + " ");
        }
        System.out.println();
    }
}

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