0

Why its not printing the numbers?

import java.util.Scanner; public class Program { public static void main(String[] args) { int count, num1 = 0, num2 = 1; System.out.println("enter number of sequence: "); Scanner scanner = new Scanner (System.in); count = scanner.nextInt(); scanner.close(); System.out.println("FIBONACCI SEQUENCE: "); int i =1; while (i<=count); { System.out.println(num1 + " "); int sumOfPrevTwo = num1 + num2; num1 = num2; num2 = sumOfPrevTwo; i++; } } }

25th Jan 2022, 8:16 AM
kafka
kafka - avatar
2 Answers
+ 3
pandora Because you have written semicolon (;) after while loop which is working till infinite times. while (i <= count); //here semicolon will break statement.
25th Jan 2022, 8:28 AM
AÍąJ
AÍąJ - avatar
+ 2
you have a semicolon after the while loop causing it to reach an infinite loop. simply change while (i<=count); into while (i<=count) will solve it.
25th Jan 2022, 8:31 AM
Shen Bapiro
Shen Bapiro - avatar