Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write in text and not on a sheet of paper thanks. Write a Java program th

ID: 3770357 • Letter: P

Question

Please write in text and not on a sheet of paper thanks.

Write a Java program that implements the following problem.
Some numbers are cyclic, that is, they repeat some pattern of themselves when multiplied by certain other numbers.For example, consider 142,857:

142857 × 1 = 142857

142857 × 2 = 285714

142857 × 3 = 428571

142857 × 4 = 571428

142857 × 5 = 714285

142857 × 6 = 857142

However, the pattern breaks with 7, as 142857 × 7 is 999999.

True cyclic numbers are rare; after 142857 the next cyclic number is 0588235294117647 which has 16 digits (notethe leading zero; such leading zeros can be important in cyclic numbers).

Rather than play with multi-digit numbers, here you are presented with an initial number, no greater than 10 digits,followed by five additional numbers. The task is to determine whether or not the product of the original numbertimes each of the other five is a cyclic pattern of the original.

Sample execution:
The first input value is the number that you will perform calculations on. Your program will read thisnumber in as well as the five multiples before the computations are performed. You must store the fivemultiples into an array called ‘multiples’ and then use the array elements to perform the calculationsdescribed above.

Your program will then return the resulting TRUE and FALSE statements as results of the multiplecomputations performed on the first value. If the result is cyclical, the answer will be TRUE.

Sample input:

142857

6

2

7

5

1

2

Sample output

TRUE

TRUE

FALSE

TRUE

FALSE

Please write in text and not on a sheet of paper thanks.

Explanation / Answer

public class Cyclic

{

    public boolean Check(int a, int b)

    {

        String x = ""+a, y = ""+b;

        int i, j , flag;

        if(x.length()!=y.length())

        return false;

        for(i=0;i<x.length();i++)

        {

            flag = 0;

            for(j=0;j<y.length();j++)

            {

                if(x.charAt(i)==y.charAt(j))

                {

                    flag = 1;

                    break;

                }

            }

            if(flag==0)

            return false;

        }

        return true;

    }

    public static void main()throws IOException

    {

        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

        int x, i, a, flag=0;

        int mul[5];

        System.out.println("Enter a number:");

        x = Integer.parseInt(r.readLine());

        System.out.println(“enter 5 numbers to multiply”);

       for(int j=0;j<5;j++)

       mul[j]= Integer.parseInt(r.readLine());

        Cyclic obj = new Cyclic();

        for(i=0;i<5;i++)

        {

            a = x*mul[i];

            if(obj.Check(x, a))

            {

                System.out.println(mul[i]+ "Cyclic Numbers: "+x+" & "+a);

                flag=1;

            }

        }

        if(flag==0)

        System.out.println("No cyclic numbers found.");

    }

}