0% found this document useful (0 votes)
6 views3 pages

Java Class for Number Operations

Uploaded by

Nihar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Java Class for Number Operations

Uploaded by

Nihar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

28/08/2024, 23:34 Write a program to define class with the following | KnowledgeBoat

STUDY MATERIAL LOGIN JOIN NOW

Computer Applications

Write a program to define class with the


following specifications:
Class name — Number
Data members/ Instance variables:
1. int n — to hold an integer number

Member methods:
1. void input() — to accept an integer number
in n
2. void display() — to display the integer
number input in n

Now, inherit class Number to another class


Check that is defined with the following
specifications:
Class name — Check
Data members/ Instance variables:
1. int fact
2. int revnum

Member methods:
1. void find() — to find and print factorial of the
number used in base class
2. void palindrome() — to check and print
whether the number used in base class is a
palindrome number or not

[A number is said to be palindrome if it


appears the same after reversing its digits.
e.g., 414, 333, 515, etc.]

Java Encapsulation & Inheritance in Java


24
Likes

[Link] 1/8
28/08/2024, 23:34 Write a program to define class with the following | KnowledgeBoat

Replay

ANSWER

import [Link];

public class Number


{
protected int n;

public void input() {


Scanner in = new Scanner([Link]);
[Link]("Enter the number:
n = [Link]();
}

public void display() {


[Link]("Number = " + n);
}
}

public class Check extends Number


{
private int fact;
private int revnum;

public void find() {


fact = 1;
for (int i = 2; i <= n; i++)
fact *= i;
[Link]("Factorial of " +
}

public void palindrome() {


revnum = 0;
int t = n;
while (t != 0) {
int digit = t % 10;
revnum = revnum * 10 + digit;
t /= 10;
}

[Link] 2/8
28/08/2024, 23:34 Write a program to define class with the following | KnowledgeBoat
if (n == revnum)
[Link](n + " is Pali
else
[Link](n + " is not
}

public static void main(String args[]) {


Check obj = new Check();
[Link]();
[Link]();
[Link]();
}
}

VARIABLE DESCRIPTION TABLE

PROGRAM EXPLANATION

OUTPUT

Answered By 11 Likes

RELATED QUESTIONS

[Link] 3/8

You might also like