Advertisements
Advertisements
Question
Define a class to overload the method display as follows:
| void display(): |
To print the following format using nested |
| void display(int n): | To print the square root of each digit of the given number |
| Example: |
n = 4329 |
Code Writing
Advertisements
Solution
class Overload_X
{
public void display()
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
public void display(int n)
{
while(n>0)
{
int r=n%10;
System.out.println(Math.sqrt(r));
n=n/10;
}
}
}shaalaa.com
Is there an error in this question or solution?
