मराठी

Write a program to enter a number and count how many to be omitted ‘1s’ are present in the number.

Advertisements
Advertisements

प्रश्न

Write a program to enter a number and count how many to be omitted ‘1s’ are present in the number.

कोड लेखन
Advertisements

उत्तर

 import java.util.*;
class clDigits
{
    void main()
    {
        Scanner sc = new Scanner(System.in);
        int N, d, count = 0;
        System.out.print("Enter a number : ");
        N = sc.nextInt();
        int cn = N;
        while(cn > 0)
        {
           d = cn%10;
           if(d=1)
           {
              count++;
           }
           cn = cn/10;
        }
        System.out.println("Number of 1 as digit in " +N+" : "+ count);
    }
}

Output:

Enter a number : 31517

Number of 1 as digit in 31517: 2

shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 11: Programs Overall - Digit Handling [पृष्ठ २५२]

APPEARS IN

रूपा पंडित Computer Applications [English] Class 10 ICSE
पाठ 11 Programs Overall
Digit Handling | Q 5. | पृष्ठ २५२
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×