Computer Science, asked by bhan61, 1 year ago



Question: A Funny Series

Consider a sequence of the form 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149…

Write a method Met which takes as parameter an integer n and prints the nth term of the above sequence. The nth term will fit in an integer value.

Hint: Does this pattern look familiar? Remember the logic for Fibonacci series?

Only write the method - assume that the Main class & main method have been defined.

Example Input: 5
Output: 4
Example Input: 8
Output: 24
Example Input: 11
Output: 149

Answers

Answered by nitish8089
6
import java.util.Scanner;
public class Program
{
public static void met(int x){
int count=0;
for(int i=1;i<=x;i++){
if(x%i==0){
count++;
}

}
if(count==2){
System.out.println(x+" :is a prime number");
}
else{
System.out.println(x+" :is not a prime number");
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Program.met(sc.nextInt());
Program.met(sc.nextInt());
}
}

nitish8089: sorry i post ur prime number qestion answer here
nitish8089: extremly sorry....
nitish8089: it's mistake...
bhan61: okkkkkkkkkkkkkkk
Similar questions