Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generating numbers from 1 to 100 to store in an array

 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
write a program to generate 100 int numbers, strore in array, then display all those numbers which are prime numbers?

but how i can print prime numbers from 1 to 100 but this whole question confused me?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muzafar Ali wrote:write a program to generate 100 int numbers, strore in array, then display all those numbers which are prime numbers?

but how i can print prime numbers from 1 to 100 but this whole question confused me?


Think of it as three steps.
1) Can you write a loop that iterates 100 times?
2) Can you create an array of those numbers?

So far, this should be easy.

Now the prime number part. How do you know if a number is prime? Try talking it out by writing here and then once you have the idea you can write it as code.
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply sir,
A prime number is a number which is self devisble, mean a number that cannot be devide with other numbers!
am i correct sir?
 
Henry Wong
author
Marshal
Pie
Posts: 21513
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muzafar Ali wrote:A prime number is a number which is self devisble, mean a number that cannot be devide with other numbers! am i correct sir?


Correct. Now how do you propose testing to see if a number is prime?

Henry
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

In program i can but when combining whole the program i can't !
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you having problems?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12202
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how would you test a number like 81 to see if it was prime? Forget about java, write it out in words. How would you start?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.wolframalpha.com/input/?i=PrimeQ[81]

So we use HTTPClient to create a request...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic