Page 197 - Computer science 868 Class 12
P. 197
Some More Programs
Program 1 Write a program to input a number and print whether the number is a neon number or not.
A neon number is a number where the sum of the digits of square of the number is equal to
the number.
Class name : neon
Data Members : int n, sum
Member Methods
neon() : Constructor to initialise the data members
void input() : Inputs n
void find_sum() : Calculates the sum of the digits of square of the number.
void display() : Checks and displays the neon number
1 import java.util.*;
2 class neon
3 {
4 int n, sum;
5 neon()
6 {
7 n=0;
8 sum=0;
9 }
10 void input()
11 {
12 Scanner sc=new Scanner(System.in);
13 System.out.print("Enter a number : ");
14 n=sc.nextInt();
15 }
16 void find_sum() // function to calculate for Neon Number
17 {
18 int sq = n * n; // stores the square of n
19 while(sq != 0)
20 {
21 sum = sum + sq % 10;
22 sq = sq / 10;
23 }
24 }
195
Statements and Scope 195

