What is wrong in my code for fibonnaci series?

	Scanner s=new Scanner(System.in);
	int n=s.nextInt();

int a=0;
int b=1;
int i=1;


while(i<=n+1)
	System.out.println(a);
int c=a+b;
	a=b;


b=c;
 
i++;
}

}

i am getting multiple o’s as output

Hi ritu,after while you have not started the bracket so it is only printing a=0 and code is going to the infinite loop as i is also not being incremented hence giving multiple zeroes.

same code you sent still not working import java.util.*; public class Main { public static void main(String args[]) { Scanner s=new Scanner(System.in); int n=s.nextInt(); int d=2; while(d<=n-1){ if(n%d==0){ System.out.println(“Not Prime”); return; } d++; } if(n==d) System.out.println(“Prime”); }}

I checked again. Its working.I don’t know how it is not working in your case.

Hi ritu,this code is correct for prime numbers,can you tell what error is shown is your case?

Hey Ritu,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.