Take Tuition from the Best Tutors
Search in
java program to print fibonacci series
The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...
public class Fibonacci {
public static void main(String[] args) {
int n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
for (int i = 1; i <= n; ++i)
{
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
}
}
}
read less class Fibonacci {
public static void main(String[] args) {
int i = 1, n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
while (i <= n)
{
System.out.print(t1 + " ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
i++;
}
}
}
public class Fibonacci {
public static void main(String[] args) {
int i = 1, n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
while (i <= n)
{
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
i++;
}
}
}
read less public class Fibonacci {
public static void main(String[] args) {
int n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
for (int i = 1; i <= n; ++i)
{
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
}
}
}
read less public
class Fibonacci
{
public static
void main(String[] args)
{ int n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
for (int i = 1; i <= n; ++i) { System.out.print(t1 + " + ");
int sum = t1 + t2; t1 = t2; t2 = sum;
}
}
}
public class Fibonacci {
public static void main(String[] args) {
int n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
for (int i = 1; i <= n; ++i)
{
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
}
}
}
read less View 59 more Answers
Related Questions
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Top Benefits of e-Learning
With the current trend of the world going digital, electronic renaissance is a new movement that is welcomed by the new generation as it helps makes the lives of millions of people easier and convenient. Along with this rapidly changing movement and gaining popularity of Internet, e-Learning is a new tool that emerging...
5 Engaging Activities For Children To Get...
Learning for every child starts from a very young age. While the formal methods include school curriculums and private lessons, the informal methods include dancing, music, drawing, and various fun-filling activities. Playing games and practising these types of activities helps the children get out of boredom and...
6 Exam Hall Tips To Follow, For Every Good Student
Appearing for exams could be stressful for students. Even though they might have prepared well, they could suffer from anxiety, tension etc. These are not good for their health and mind. However, following a few exam preparation tips can save them from all these and help them to score good marks. Let’s find out all...
The Trend of E-learning and it’s Benefits
E-learning is not just about delivering lessons online. It has a much broader scope that goes beyond manual paper or PowerPoint Presentations. To understand the reach of E-learning and how the whole process works in developing the Educational system, we will discuss a few points here. Let us find out how this new learning...
Looking for Tuition ?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for Tuition Classes are on UrbanPro
The best Tutors for Tuition Classes are on UrbanPro