David is following an exercise regime where on first,
second and third day he works out for 1, 2 and 3 minutes.
After 3 days, his workout duration is sum of the 3 previous days.
What is his workout duration (in minutes) after ‘n’ days, where n is greater than 4.
Answers
Answered by
6
Answer:
import java.util.ArrayList;
import java.util.Scanner;
public class David
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
if(n<4)
{
System.out.println("Invalid");
}
else
{
ArrayList<Integer> arr=new ArrayList<>();
arr.add(0,1);
arr.add(1,2);
arr.add(2,3);
int x=0;
for(int i=3;i<n;i++)
{
x =arr.get(i-3)+arr.get(i-2)+arr.get(i-1);
arr.add(i,x);
}
System.out.println(arr.get(n-1));
}
}
}
Explanation:
Similar questions
India Languages,
1 month ago
Social Sciences,
2 months ago
Hindi,
2 months ago
Math,
9 months ago
Math,
9 months ago