常用的一些demo代码的显示工具编写尝试

常用的一些demo代码的显示工具编写尝试

@version 1.0 */ public class MyUtil {

/**

By default, initialize constant */ static { separationMarkCount = 0; }

static Random r = new Random();

//工具类无需创建对象,所以把其构造器私有化 private MyUtil() { }

/**

Due to param n , create n bit of verification code

@param n n bit of verification code

@return verification code String */ public static String createVerifyCode(int n) { String code = “”; String standard = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”;

Random r = new Random(); for (int i = 0; i < n; i++) { int index = r.nextInt(n); code += standard.charAt(index); } return code; }

/**

return an positive int Array which has amout size of integer Array

in the range of 0 to magnitude

notice :

amount and magnitude is param name

example:

if you use by that,MyUtil.createIntArray(4,100).

this method can do.return new int[]{1,21,55,3};

@param amount Array’s size

@param magnitude Array’s range

@return int[] Array */ public static int[] createIntArray(int amount, int magnitude) {

/**

对数器 (use to compare digital ) */

int[] nums = new int[amount];

for (int i = 0; i < nums.length; i++) { nums[i] = r.nextInt(magnitude + 1); }

return nums; }

/**

print a init Array .now the array should be int[] type.@param nums a int[] type array@version 1.0 */ public static void printInitArray(int[] nums) { System.out.print(“show init Array :”); System.out.println(Arrays.toString(nums)); }

/**

By now, this method is for printing Demo’s Separation Markfor a clear show.

caution: this method uses a static block to initialize the value. this method is a single thread. @date 20231231@author yangguoxi */ private static int separationMarkCount = 0;

public static void printSeparationMark() { separationMarkCount++; System.out.println(“" + separationMarkCount + "=”);

}

/**

print your mark for demo show by param you input;

for example :

(1)

(2)

(a)

@param rank marks you like */ public static void printSeparationMark(Object rank) { //subclass’s toString method will be use . if (Objects.isNull(rank)) { return; }

System.out.println(“(” + rank + “)”); System.out.println();

}

/**

if you input an int number, this method can return the int digital array.

example:if you input an int value ,such as 153this method can do.return new int[]{3,5,1};

In the array, starting from the lower subscript,the numeric bits of the number are stored in order from the lower to the higher subscript@param inputNumber any int number you want@return int array that storage into this array@author yangguoxi@date before 20230301 */

public static int[] getIntNumberArray(int inputNumber) { /** * procedures: * * - 1. get the digit size of the number. * - 2. storage every digit to the int array. * * * * * * ps: * this achievement way is a very Brute force algorithm to advance this requirement. * so, the first step is to get how much this int digit has. * the next step is to get every digit from this int param number. */ int digit = 0; // stroage the lower digit int arraySize = 0; int[] intDigitalArray = null; int number = inputNumber;

// - 1. get the digit size of the number. while (number > 0) { digit = number % 10; System.out.println(digit); number = number / 10; arraySize++; } //- 2. storage every digit to the int array. number = inputNumber; intDigitalArray = new int[arraySize]; for (int index = 0; number > 0; index++) { digit = number % 10; number = number / 10; intDigitalArray[index] = digit; } return intDigitalArray;

}


比丘资源网 » 常用的一些demo代码的显示工具编写尝试

发表回复

提供最优质的资源集合

立即查看 了解详情