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

1. Member
Join Date
Nov 2012
Posts
5
Rep Power
0

## 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

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

Do we need to repeat this advice every time you post code?

db

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

Why are you asking the user for a 'Number' (and store it in 'num')? You don't do anything with the bounds L1 and L2 either so your outer loop never ends (or it won't even start, depending on the values of L1 and L2)

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•