Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class Main {
- static long FindNumber(int i) {
- long Number = i, Prev = 0, Step = 1, Digit = i;
- do {
- Step *= 10;
- Number += Step * ((Digit * 2) % 10 + Prev);
- Prev = (Digit * 2) / 10;
- Digit = Number / Step;
- } while ((Digit != i) || (Prev != 0));
- Number -= Digit * Step;
- return Number;
- }
- static void GetArray(long[] MyArr) {
- System.out.printf("This program searches for the smallest number, which, when you rearrange the last digit\n" +
- "to the first one, is twice as large as the original\n");
- System.out.printf("This is the list of required numbers :\n");
- for (int i = 0; i < 7; i++) {
- MyArr[i] = FindNumber(i + 2);
- System.out.println(i + 1 + ":" + MyArr[i]);
- }
- }
- static void ShowAnswer(long[] MyArray) {
- long Min = MyArray[6];
- for (int i = 0; i < 7; i++)
- if (MyArray[i] < Min)
- Min = MyArray[i];
- System.out.println("Minimum required number is : " + Min);
- }
- public static void main(String[] args) {
- long[] MyArray = new long[7];
- GetArray(MyArray);
- ShowAnswer(MyArray);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement