Computer Science, asked by Anonymous, 7 months ago

get a number, check whether the number ends with 9. java program needed .!!!!!!! please I need the full program!!!!!!!​

Answers

Answered by SuhailAbdulSathar
1

Explanation:

GEEKSFORGEEKS

Find the Number which contain the digit d

Given two integer number n and d. The task is to find the number between 0 to n which contain the specific digit d.

Examples:

Input : n = 20 d = 5 Output : 5 15 Input : n = 50 d = 2 Output : 2 12 20 21 22 23 24 25 26 27 28 29 32 42

Approach 1:

Take a loop from 0 to n and check each number one by one, if the number contains digit d then print it otherwise increase the number. Continue this process until loop ended.

C++

// CPP program to print the number which

// contain the digit d from 0 to n

#include <bits/stdc++.h>

using namespace std;

  

// Returns true if d is present as digit

// in number x.

bool isDigitPresent(int x, int d)

{

    // Breal loop if d is present as digit

    while (x > 0)

    {

        if (x % 10 == d)

            break;

  

        x = x / 10;

    }

  

    // If loop broke

    return (x > 0);

}

  

// function to display the values

void printNumbers(int n, int d)

{

    // Check all numbers one by one

    for (int i = 0; i <= n; i++)

  

        // checking for digit

        if (i == d || isDigitPresent(i, d))

            cout << i << " ";

}

  

// Driver code

int main()

{

    int n = 47, d = 7;

    printNumbers(n, d);

    return 0;

}

Java

Python 3

C#

PHP

Output:The number of values are 7 17 27 37 47

Approach 2:

This approach uses every number as a String and checks digit is present or not. This approach use of String.indexOf() function to check if the character is present in the string or not.

String.indexOf() >= 0 means chaaracter is present

and String.indexOf() = -1 means character is not present

C++

// CPP program to print the number which 

// contain the digit d from 0 to n

#include<bits/stdc++.h>

using namespace std;

  

GEEKSFORGEEKS

Find the Number which contain the digit d

Given two integer number n and d. The task is to find the number between 0 to n which contain the specific digit d.

Examples:

Input : n = 20 d = 5 Output : 5 15 Input : n = 50 d = 2 Output : 2 12 20 21 22 23 24 25 26 27 28 29 32 42

Approach 1:

Take a loop from 0 to n and check each number one by one, if the number contains digit d then print it otherwise increase the number. Continue this process until loop ended.

C++

// CPP program to print the number which

// contain the digit d from 0 to n

#include <bits/stdc++.h>

using namespace std;

  

// Returns true if d is present as digit

// in number x.

bool isDigitPresent(int x, int d)

{

    // Breal loop if d is present as digit

    while (x > 0)

    {

        if (x % 10 == d)

            break;

  

        x = x / 10;

    }

  

    // If loop broke

    return (x > 0);

}

  

// function to display the values

void printNumbers(int n, int d)

{

    // Check all numbers one by one

    for (int i = 0; i <= n; i++)

  

        // checking for digit

        if (i == d || isDigitPresent(i, d))

            cout << i << " ";

}

  

// Driver code

int main()

{

    int n = 47, d = 7;

    printNumbers(n, d);

    return 0;

}

Java

Python 3

C#

PHP

Output:The number of values are 7 17 27 37 47

Approach 2:

This approach uses every number as a String and checks digit is present or not. This approach use of String.indexOf() function to check if the character is present in the string or not.

String.indexOf() >= 0 means chaaracter is present

and String.indexOf() = -1 means character is not present

C++

// CPP program to print the number which 

// contain the digit d from 0 to n

#include<bits/stdc++.h>

using namespace std;

  

Answered by Anonymous
2

Answer:

seri pa, help na kelu enkitta....gud nite

Similar questions