Question 9

3 comments on “Question 9”


  • Pratik

    def kaprekarNumbers(p,q):
    result = []
    for i in range(p,q+1):
    sqr = str(i**2)
    n = len(sqr)
    if i == 1:
    result.append(i)
    elif n>1 and i == int(sqr[:n//2])+int(sqr[n//2:])
    result.append(i)

    if len(result) == 0:
    print(“INVALID RANGE”)
    else:
    print(*result)

    p = int(input())
    q = int(input())
    kaprekarNumbers(p,q)


  • Gangadhar

    import java.util.ArrayList;
    import java.util.Scanner;

    public class Solution {

    public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    System.out.println(“Enter num range:”);
    int p = sc.nextInt();
    int q = sc.nextInt();
    sc.close();

    ArrayList theSpecialNumber = getTheSpecialNumber(p,q);

    for (Integer integer : theSpecialNumber) {
    System.out.print(integer+” “);
    }
    }

    private static ArrayList getTheSpecialNumber(int p, int q) {
    ArrayList list = new ArrayList();
    for (int i = p; i <=q ; i++) {

    if (i<4) {
    if (i==1) {
    list.add(i);
    }
    }else{
    int d = noOfDigits(i);
    int divFact = 1;
    for (int j = 0; j 0) {
    i=i/10;
    count++;
    }
    return count;
    }

    }


    • Gangadhar

      //noOfDigit mentod called in above code
      private static int noOfDigits(int i) {
      int count=0;
      while (i>0) {
      i=i/10;
      count++;
      }
      return count;
      }