Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Write a Java program that displays the prime numbers between A and B
Process by which instructions are given to a computer, software program, or application using code.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
Program:
import java.util.*;
public class Main {
public static void main(String[] args) {
int A, B;
Scanner x = new Scanner (System.in);
System.out.print ("Enter the starting number of prime number A: ");
A = x.nextInt();
System.out.print ("Enter the ending number of prime number B: ");
B = x.nextInt ();
System.out.println ("The prime numbers between A and B:");
while (A < B) {
boolean flag = false;
for(int i = 2; i <= A/2; ++i) {
// condition for nonprime number
if(A % i == 0) {
flag = true;
break;
}
}
if (!flag && A != 0 && A != 1)
System.out.print(A + " ");
++A;
}
System.out.println("\n");
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images