Results 1 to 3 of 3
- 12-11-2012, 11:47 AM #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
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
- 12-11-2012, 04:19 PM #2
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?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-11-2012, 06:03 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Find a prime number
By bam207 in forum New To JavaReplies: 2Last Post: 11-16-2012, 06:42 PM -
Prime Number finder
By hoosierfan24 in forum New To JavaReplies: 11Last Post: 02-17-2011, 09:13 AM -
fibonnaci number between limits?
By Manish87 in forum Java AppletsReplies: 14Last Post: 09-27-2010, 07:26 AM -
How to Determine prime number and making shape using loop?
By cyzash in forum New To JavaReplies: 10Last Post: 02-20-2010, 08:25 PM -
Prime Number - System print all the prime numbers ...
By pinkdreammsss in forum New To JavaReplies: 20Last Post: 04-26-2009, 01:50 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks