Page 198 - Computer science 868 Class 12
P. 198
25 void display()
26 {
27 if(sum==n)
28 System.out.println(n+ " is neon number");
29 else
30 System.out.println(n+ " is not neon number");
31 }
32 public static void main()
33 {
34 neon ob = new neon();
35 ob.input();
36 ob.find_sum();
37 ob.display();
38 }
39 }
The output of the preceding program is as follows:
OUTPUT 1
Enter a number : 9
9 is neon number
OUTPUT 2
Enter a number : 45
45 is not neon number
Program 2 Write a method fib(int) to find the sum of all the Fibonacci numbers up to nth term.
Fibonacci numbers up to 5are: 0 , 1 , 1 , 2 , 3
Here, the sum of the numbers is 7.
1 import java.util.*;
2 class fibonacci
3 {
4 // Function to find the nth Fibonacci number
5 int fib(int n)
6 {
7 int sum=0, a=0, b=1, curfibo;
8 if(n<=1)
9 {
196196 Touchpad Computer Science-XII

