473,667 Members | 2,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3883
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.le ngth;i++) {
if(primes[i]!=0) {
System.out.prin t(primes[i]);
System.out.prin t("\t");
}
}
System.out.prin t("\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.prin tln(i);
}
}
display();
}

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

"Roy J" <be******@comca st.net> wrote in message news:<G_5Fc.121 54$IQ4.8981@att bi_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
7380
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 atmosphere. Good food.", " (Harry Houdini - 03/01/2004)"); INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada", " (Herbert Hoover - 03/03/2004)"); INSERT INTO `reviews` VALUES("", "Golden Dragon", "Lunch", "Exquisite.
1
6083
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 Cart</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="StyleSheet" href="css/style.css" type="text/css">
2
2931
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 where there is no scripts allowed running (the software is from Opentext called Livelink)- therefore I need javascript to do the tasks listed below: 1. validate the form - this has been completed 2. pop up another window that will go ahead and...
48
3224
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 "huge" Indy is both as a project, in support, development, and use. But Indy is new to the .net world. Indy is a HUGE library implementing over 120 internet protocols and standards and comes with complete source. Its an open source project, but not...
23
2532
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
2736
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 the sequence nos and it should be such that i can access it through the structure .plz help me .
5
1190
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 __init__(self, now here I need to put array's constructor parameters..., then mine): array.array.__init__(self, typecode)
1
1324
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 following methods. a. A constructor that creates an integer array of the size specified. b. A method that getArraySize. c. A method that accepts x as integer input parameter (positive or negative). If the number x is positive, converts it to...
0
7110
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 the due date 10% of the grade is taken off. I think I'm coming down with the flu and my brain is just not processing this assignment. Here is the assignment: Modify the Inventory program by adding a button to the GUI that allows the user to move...
0
1525
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 name is displayed in a list box. but the grades need to be stored in an array. here is a portion of my code: Public Class btnAdd Dim grades() As Double Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As...
0
8458
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8565
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7391
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.