# A number is Prime or Composite between two given limits using Nested-while loop.

• 12-11-2012, 12:47 PM
UmairBaloch
A number is Prime or Composite between two given limits using Nested-while loop.
Hi guys,I'm trying to make a program that takes input from user and determines if a number is Prime or composite, I have to give two limits, upper and lower one, and I have to make the program using nested while loop
import java.util.Scanner;

class Pr{
public static void main(String a[]){
int L1, L2, count, check;
Scanner scan = new Scanner(System.in);

System.out.print("Enter the lower limit: ");
L1 = scan.nextInt();

System.out.print("Enter the upper limit: ");
L2 = scan.nextInt();

System.out.print("Enter the Number: ");
int num = scan.nextInt();

while (L1<=L2){
check = 0;
count = 2;

while(count<L1){
if (L1%count==0)
check++;
count++;

}
if (check>0)
System.out.print("Composite");
else
System.out.print("Prime");

}

}
}

it is sort of showing reverse result, eg 64 is prime and 79 is composite,
so any of you guys might wanna help, will be highly appreciated
• 12-11-2012, 05:19 PM
DarrylBurke
Re: A number is Prime or Composite between two given limits using Nested-while loop.