SHARE
TWEET

Untitled

a guest Oct 15th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2. public class Main {
  3.     static long FindNumber(int i) {
  4.         long Number = i, Prev = 0, Step = 1, Digit = i;
  5.         do {
  6.             Step *= 10;
  7.             Number += Step * ((Digit * 2) % 10 + Prev);
  8.             Prev = (Digit * 2) / 10;
  9.             Digit = Number / Step;
  10.         } while ((Digit != i) || (Prev != 0));
  11.         Number -= Digit * Step;
  12.         return Number;
  13.     }
  14.     static void GetArray(long[] MyArr) {
  15.         System.out.printf("This program searches for the smallest number, which, when you rearrange the last digit\n" +
  16.                 "to the first one, is twice as large as the original\n");
  17.         System.out.printf("This is the list of required numbers :\n");
  18.         for (int i = 0; i < 7; i++) {
  19.             MyArr[i] = FindNumber(i + 2);
  20.             System.out.println(i + 1 + ":" + MyArr[i]);
  21.         }
  22.     }
  23.     static void ShowAnswer(long[] MyArray) {
  24.         long Min = MyArray[6];
  25.         for (int i = 0; i < 7; i++)
  26.             if (MyArray[i] < Min)
  27.                 Min = MyArray[i];
  28.         System.out.println("Minimum required number is : " + Min);
  29.     }
  30.     public static void main(String[] args) {
  31.         long[] MyArray = new long[7];
  32.         GetArray(MyArray);
  33.         ShowAnswer(MyArray);
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top