Advertisements
Advertisements
Question
Write the program in Java to display the first ten terms of the following series:
0, 1, 2, 3, 6, ................
Answer in Brief
Solution
public class Q1a
{ public static void main(String args[])
{ int a = 0, b = 1, c = 2, d = 0;
System.out.println("TRIBONACCI SERIES"); // optional
System.out.print(a + "," + b + "," + c + ",");
for (int i = 1; i <= 10; i++)
{ d = a + b + c;
System.out.print(d + ",");
a = b;
b = c;
c = d;
}
}}
shaalaa.com
Is there an error in this question or solution?
Chapter 1.09: Iterative Constructs in Java - EXERCISES [Page 124]