Prime Numbers : Prime Numbers « Number « Ruby






Prime Numbers


require 'mathn'

prime_number = Prime.new # instantiate a Prime object
prime_number.next # => 2 # return the next prime number (seed = 1)
prime_number.succ # => 3 # succ works, too

# print the next prime number as a string
puts "The next prime number is " + prime_number.next.to_s + "."

 








Related examples in the same category

1.Use Prime to generate prime numbers
2.Generates 25 prime numbers from 2 to 97
3.Use each method from Prime class
4.Generating Prime Numbers with succ
5.Pass code block into each