473,387 Members | 1,569 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,387 software developers and data experts.

need help on array please

Hello everyone:)
My name is Roy, I am new to Java and I have problem regarding to arrays.
if you have time and like to help, please help.

I am trying to make a program to deal with prime numbers, but I do not how
to involve arrays with that.

program generates prime numbers according to user input, and displays them
in descending order. The user enters the number of prime numbers to be
generated. The output is displayed 5 numbers per row, 20 rows per screen.
If there are more than 100 numbers, the output should wait for the user to
press <Enter> before continuing to the next page. The program should repeat
until the user chooses to quit.

The "primelist" data structure must be implemented as a class with a private
array and a private counter for the number of elements. The class should
include methods to fill the array, display the array, etc.. The method to
test a number for "primeness" be a private method.

my quetion regarding the array stuff, how i can create a method to fill
array 5 number each row and display them in screen with display method?

thanks alot
waiting
Jul 17 '05 #1
1 3859
Hello Roy,

I have written small program which can be of help. Try it.

************************************************** *********************

public class PrimeList {

private static int[] primes ;
private static int count;
/** Creates a new instance of PrimeList */
public PrimeList() {
}

public static boolean testPrime(int i) {
boolean ret = false;
for(int j=2;j<i-1;j++) {
if(i%j == 0) {
ret = true;
}
}
return ret;
}

public static void display() {
for(int i=0;i<primes.length;i++) {
if(primes[i]!=0) {
System.out.print(primes[i]);
System.out.print("\t");
}
}
System.out.print("\n");
}

public static void main(String[] args) {
count =0;
primes = new int[5];
for(int i =1;i<100;i++) {
if(!testPrime(i)) {
if(count%5 ==0) {
display();
primes = new int[5];
count=0;
}
primes[count] = i;
count++;
//System.out.println(i);
}
}
display();
}

}
************************************************** *******************

"Roy J" <be******@comcast.net> wrote in message news:<G_5Fc.12154$IQ4.8981@attbi_s02>...
Hello everyone:)
My name is Roy, I am new to Java and I have problem regarding to arrays.
if you have time and like to help, please help.

I am trying to make a program to deal with prime numbers, but I do not how
to involve arrays with that.

program generates prime numbers according to user input, and displays them
in descending order. The user enters the number of prime numbers to be
generated. The output is displayed 5 numbers per row, 20 rows per screen.
If there are more than 100 numbers, the output should wait for the user to
press <Enter> before continuing to the next page. The program should repeat
until the user chooses to quit.

The "primelist" data structure must be implemented as a class with a private
array and a private counter for the number of elements. The class should
include methods to fill the array, display the array, etc.. The method to
test a number for "primeness" be a private method.

my quetion regarding the array stuff, how i can create a method to fill
array 5 number each row and display them in screen with display method?

thanks alot
waiting

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
1
by: bin_P19 P | last post by:
the code i have got is as follows and now im stuck <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Shopping...
2
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
23
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
5
by: SpreadTooThin | last post by:
If you are deriving a new class from another class, that you must (I assume) know the initializer of the other class. So in myClass import array class myClass(arrary.array): def...
1
by: al mwaj3 | last post by:
please I need help in this problem, I must send it tomorrow the problem is (1) Write a Java class called: Binary that has two data fields: an integer array, and an integer size as well as the...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
0
by: jac130 | last post by:
i need to populate an array with grades. there is an 'add students & grades' button. user is prompted by input box to enter a students name, then another input box to enter their grade. the student's...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.