Define a class Sample described as below:
Instance variables:
n: To enter the first number
m: To enter the second number
sum: To store the sum of prime factors of n
pro: To store the product of digits of m
Member methods:
void input (): To enter the numbers
void findsum(): to find the sum of prime factors of n
void findpro(): to find the product of digits of m
void display (): to print the sum and product
Write a main () function to create an object of the class and call the above methods
import java.util.*;
class Sample
{
int n,m,sum=0,pro=1;
void input()
{
Scanner ob=new Scanner(System.in);
System.out.println("Enter the first no"):
n=ob.nextInt();
System.out.println("Enter the second no");
m=ob.nextInt();
}
void findsum()
{
int i;
for(i=2;i<n/2;i++)
{
if(n%i==0)
{
sum=sum+i;
}
}
}
void findpro()
{
int d;
int a;
a=m;
while(a!=0)
{
d=a%10;
pro=pro*d;
a=a/10;
}
}
void display()
{
System.out.println("The sum is"+sum);
System.out.println("The product is"+pro);
}
void main()
{
Sample ob2=new Sample();
ob2.input;
ob2.findsum();
ob2.findpro();
ob2.display();
}
}