• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Predict Sequence of Numbers?!

Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following qn and I am in doubt how to get started. I have a few formulas but the problem is I am uncertain how to equate in Java.

From the start program, I would provide a series of numbers and based on the numbers, I have to equate to see which best fits into the formula. It has to determine which type(s) of sequence these numbers could belong to, and in each case predict the next five numbers in the sequence.

Formulas are
Constant uk = a
Arithmetic uk = uk-1+b
Geometric uk = ruk-1
Recurrent uk = auk-1 + buk-2 + c

Appreciate your help!!!
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a homework question and certainly not advanced Java - more like beginner. But it's Friday and I'm feeling generous, so some clues anyway...

Look at the given numbers. If they're all the same, it's constant series.

Look at the differences between the given numbers. If all the differences are the same, it's arithmetic.

Look at the ratios of adjacent given numbers. If the ratios are all the same, it's geometric. Take care: if you use integer arithmetic, you could get false positives here. But if you use floating-point, you could get false negatives, unless you round appropriately.
There’s no place like But I'll always remember this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic