मराठी

Define a class to overload the method display as follows :void display(): To print the following format using nested looр 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 void display(int n):

Advertisements
Advertisements

प्रश्न

Define a class to overload the method display as follows:

void display():

To print the following format using nested
looр
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

void display(int n): To print the square root of each digit of the given number
Example:

n = 4329
output -3.0
     1.414213562
     1.732050808
     2.0

कोड लेखन
Advertisements

उत्तर

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
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 3: User-Defined Methods - Exercises [पृष्ठ ९५]

APPEARS IN

रूपा पंडित Computer Applications [English] Class 10 ICSE
पाठ 3 User-Defined Methods
Exercises | Q 9. | पृष्ठ ९५
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×