Page 498 - CA_Blue( J )_Class10
P. 498
int d,s=O,c=O;
while(n>O)
{
d=n%10;
s=s+d;
c++;
n=n/10;
}
if(s==c)
return true;
else
return false;
}
}
8. Define a class to overload the method display() as follows: [15]
void display() : To print the following format using nested loop.
1 2 1 2 1
1 2 1 2 1
1 2 1 2 1
void display (int n, int m): To print the quotient of the division of m and n if m is greater than n otherwise print the sum of
twice n and thrice m.
double display (double a, double b, double c): To print the value of z where
z = p × q
a + b
p = – c q = a + b + c [Understanding Application]
Ans. class overload
{
void display()
{
int r,c;
for(r=l;r<=3;r++)
{
for(c=1;c<=5;c++)
{
if(c%2==0)
System.out.print(2);
else
System.out.print(1);
}
System.out.println();
}
}
void display(int m, int n)
{
if(m>n)
System.out.println(m/n);
else
System.out.println(2 *n+3*m);
}
void display(double a,double b, double c)
{
double z, p, q;
p=(a+b)/c;
q=a+b+c;
z=p*q;
System.out.println(z);
}
}
496496 Touchpad Computer Applications-X

