Answer to Question #257515 in Java | JSP | JSF for Nikhil Sahoo

Question #257515

Write a program in java to display first 20 numbers of Harsh Series: 1, 2, 5, 12, 29, 70 using following method prototype: void harsh_series()

Hint: The series starts with 1 & 2 and subsequent numbers are the sum of twice the previous number and number previous to previous number.


1
Expert's answer
2021-10-30T23:55:48-0400
import java.util.Scanner;
public class Main  {
static void harsh_series(){
    {
	int x,m=1,n=0,y;
    System.out.println("First 20 Harsh series: ");
    for(x=1; x<=20; x++)
     {
      y= m + 2*n;
      System.out.print(y+" ");
      m = n;
      n = y;
     }
   }
}
    public static void main(String args[]){
    harsh_series();
 }}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS