Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. package com.company;
  2. public class Main {
  3.     static long FindNumber(int i) {
  4.         long Number = i;
  5.         long Prev = 0;
  6.         long Step = 1;
  7.         long Digit = i;
  8.         do {
  9.             Step *= 10;
  10.             Number += Step * ((Digit * 2) % 10 + Prev);
  11.             Prev = (Digit * 2) / 10;
  12.             Digit = Number / Step;
  13.         } while ((Digit != i) || (Prev != 0));
  14.         Number -= Digit * Step;
  15.         return Number;
  16.     }
  17.     static void GetArray(long[] MyArr) {
  18.         System.out.printf("This program searches for the smallest number, which, when you rearrange the last digit\n" +
  19.                 "to the first one, is twice as large as the original\n");
  20.         System.out.printf("This is the list of required numbers :\n");
  21.         for (int i = 0; i < 7; i++) {
  22.             MyArr[i] = FindNumber(i + 2);
  23.             System.out.println(i + 1 + ":" + MyArr[i]);
  24.         }
  25.     }
  26.     static void ShowAnswer(long[] MyArray) {
  27.         long Min = MyArray[6];
  28.         for (int i = 0; i < 7; i++)
  29.             if (MyArray[i] < Min)
  30.                 Min = MyArray[i];
  31.         System.out.println("Minimum required number is : " + Min);
  32.     }
  33.     public static void main(String[] args) {
  34.         long[] ArrayNumber = new long[7];
  35.         GetArray(ArrayNumber);
  36.         ShowAnswer(ArrayNumber);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement