Results 1 to 3 of 3
  1. #1
    UmairBaloch is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Post 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
    I've made this so far
    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. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

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

    You were told about the code tags in your previous thread: I want to convert this If-Else Statement program to Switch Statement

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

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Find a prime number
    By bam207 in forum New To Java
    Replies: 2
    Last Post: 11-16-2012, 06:42 PM
  2. Prime Number finder
    By hoosierfan24 in forum New To Java
    Replies: 11
    Last Post: 02-17-2011, 09:13 AM
  3. fibonnaci number between limits?
    By Manish87 in forum Java Applets
    Replies: 14
    Last Post: 09-27-2010, 07:26 AM
  4. Replies: 10
    Last Post: 02-20-2010, 08:25 PM
  5. Prime Number - System print all the prime numbers ...
    By pinkdreammsss in forum New To Java
    Replies: 20
    Last Post: 04-26-2009, 01:50 AM

Posting Permissions

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