473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

prime numbers

Hello,I neead help with simple program in java.First test prime numbers with use array and second with use two method,thank.
Simi.
Oct 23 '06 #1
6 2126
r035198x
13,262 8TB
Hello,I neead help with simple program in java.First test prime numbers with use array and second with use two method,thank.
Simi.
Surely you should have some ideas of your own on how to do this. Why don't you post the ideas then others can add their own.
Oct 23 '06 #2
I need modify this code.

for(int pp=2;pp<100;pp++) //pp=possible prime
{
for(int pd=2;pd<pp;pd++) //pd=possible divisor
{
if(pp%pd==0)
break;
}
if(pp==pd)
System.out.println(pp);
}
Oct 23 '06 #3
r035198x
13,262 8TB
I need modify this code.

for(int pp=2;pp<100;pp++) //pp=possible prime
{
for(int pd=2;pd<pp;pd++) //pd=possible divisor
{
if(pp%pd==0)
break;
}
if(pp==pd)
System.out.println(pp);
}
Expand|Select|Wrap|Line Numbers
  1. public class Primes {
  2.     public static void main(String[] args) {
  3.         int pp, pd = 0;
  4.         for(pp=2;pp<100;pp++) //pp=possible prime
  5.         {
  6.         for(pd=2;pd<pp;pd++) //pd=possible divisor
  7.         {
  8.         if(pp%pd==0)
  9.         break;
  10.         }
  11.         if(pp==pd)
  12.         System.out.println(pp);
  13.         }
  14.     }
  15. }
This will print all primes from 2 - 97. What exactly do you want to do?
Oct 23 '06 #4
I donīt know how pp replace by array obout 100 numbers?
Oct 23 '06 #5
r035198x
13,262 8TB
I donīt know how pp replace by array obout 100 numbers?
Do you mean that you want to store the primes in an array of size 100? You would do it this way:

Expand|Select|Wrap|Line Numbers
  1. public class Primes {
  2.         public static void main(String[] args) {
  3.     int[] primes = new int[100];
  4.     int i = 0;
  5.     int pp, pd = 0;
  6.     for(pp=2;pp<100;pp++) //pp=possible prime
  7.     {
  8.          for(pd=2;pd<pp;pd++) //pd=possible divisor
  9.              {
  10.         if(pp%pd==0)
  11.         break;
  12.         }
  13.         if(pp==pd)
  14.         primes[i++] = pp;
  15.         }
  16.         for(int p: primes) {
  17.             System.out.println(p);
  18.         }
  19.  
  20.     }
  21. }
I'm sorry, but you are not being very clear
Oct 23 '06 #6
I am much obliged with the help of.
Oct 23 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

36
by: Dag | last post by:
Is there a python module that includes functions for working with prime numbers? I mainly need A function that returns the Nth prime number and that returns how many prime numbers are less than N,...
9
by: Greg Brunet | last post by:
In doing some testing of different but simple algorithms for getting a list of prime numbers, I ended up getting some results that seem a bit contradictory. Given the following test program...
11
by: don | last post by:
Ok, this is a homework assignment, but can you help me out anyway...... I need a routine for figuring out if a number inputted by the user is a prime number or not...... all I'm asking for is Not...
0
by: AshifToday | last post by:
this was my and my frineds little project in earlier classes, the program seperates the composite and prime numbers in two sections of the screen ===================== /* This program has...
0
by: ETM11871 | last post by:
i need to develop a code that finds a prime right number between 2 and 100000. and print one line of text that indicates if the int. is right prime. i am in beginning programing so complex is...
25
by: johnmsimon | last post by:
i need to develop a code that finds a prime right number between 2 and 100000. and print one line of text that indicates if the int. is right prime. i am in beginning programing so complex is...
60
by: rhle.freak | last post by:
Here is my code to generate prime numbers.It works absolutely fine when the range is *not very large*. However on initializing i with a large integer it produces erroneous results (some numbers...
7
by: newstips6706 | last post by:
1, 2, 3, 5, 7... PRIME Numbers ________________________________ Definitions What is a PRIME Number ?
7
by: Caffiend | last post by:
Well, I've been picking at learning python, got tired of reading, and figured I'd try to replicate my prime number generator I wrote (with much TSDN forum help) in C++. I've hit a stumbling block......
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.