हिंदी

Define a class to overload the function print as follows: void print() to print the following format 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 void print(int n)

Advertisements
Advertisements

प्रश्न

Define a class to overload the function print as follows:

void print() to print the following format
  1 1 1 1
  2 2 2 2
  3 3 3 3
  4 4 4 4
  5 5 5 5
void print(int n) To check whether the number is a lead number. A lead number is one whose sum of even digits is equal to the sum of odd digits.
 

e.g. 3669 odd digits sum = 3 + 9 = 12
                even digits sum = 6 + 6 = 12
3669 is a lead number.

कोड लेखन
Advertisements

उत्तर

public class Printclass
{
   //instance variables - replace the example below with your own public void print() 
{
    for(int i=1;i<=5;i++)
       {for(int j=1;j<=5;j++)
           System.out.print(i+" ");
       System.out.println("\n");}
}
public void print(int n)
{
   int se=0,d=0,so=0; 
   while (n>0)
   {
       d=n%10;
       if (d%2=0)
           se+=d;
       else
            so+=d;
        n/=10;
   } 
   if (se==so)
       System.out.println("Lead number");
   else
   System.out.println("Not a Lead number");
}
public static void main(String [] args)
{
     Printclass ob=new Printclass();
     ob. print(); 
     ob.print(1542);
  }
}
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 1: Revision of Class 9 Syllabus - Exercises [पृष्ठ ५०]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 1 Revision of Class 9 Syllabus
Exercises | Q 17. | पृष्ठ ५०
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×