Computer Applications
Define a class to accept a number and check whether the number is Neon or not. A number is said to be Neon if sum of the digits of the square of the number is equal to the number itself.
E.g.
Input: 9
Output:
9 * 9 = 81, 8 + 1 = 9
9 is Neon number.
Java
Java Iterative Stmts
55 Likes
Answer
import java.util.Scanner;
public class NeonNumber
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the number to check: ");
int n = in.nextInt();
int sq = n * n;
int sqSum = 0;
while (sq != 0) {
int d = sq % 10;
sqSum += d;
sq /= 10;
}
if (sqSum == n)
System.out.println("Neon Number");
else
System.out.println("Not a Neon Number");
}
}
Output


Answered By
25 Likes
Related Questions
If
int a[] = {7, 3, 4, 8, 9, 2};
what are the values of x and y?(a) x = a[1] * a[0] + a[3]
(b) y = a.length
Write the return types of the following library functions:
(a)
isLetterOrDigit(char)
(b)
replace(char, char)
Define a class Student described as below
Data members/instance variables
name, age, m1, m2, m3 (marks in 3 subjects), maximum, averageMember methods
(i) Student (…) : A parameterised constructor to initialise the data members.(ii) compute() : To compute the average and the maximum out of three marks.
(iii) display() : To display the name, age, marks in three subjects, maximum and average.
Write a main method to create an object of a class and call the above member methods.
Define a class to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique.