顺便说一下,这是在 java 中完成的。
所以我试图用字符创建某种模式生成器。我目前拥有的代码将创建一个数组,它将从输入的第一个数字开始无限打印,直到最后一个数字,从第一个数组中获取字符。错误是,如果我从接近尾声开始并告诉它复制更多;(比如说从 12 个字符开始,再复制 15 个字符,但原始数组中只有 14 个字符。)如何让它在原始数组结束后继续填充数组,比如从头开始并继续通过数组直到填满。\
import java.util.*;
public class patternGenerator {
private static Scanner input;
public static void main(String[] args) {
char[] anArray = {'!','@','#','$','%','^','&','*','+','=','~','<','>','?'};
int symbolsPerLine = 0, printed, dontStop = 1, difSymbols;
input = new Scanner(System.in);
System.out.println("Enter the amount of symbols to use: ");
difSymbols = input.nextInt();
while (difSymbols > anArray.length) {
difSymbols = (anArray.length-1);
}
System.out.println("Dif symbols are: "+ difSymbols);
System.out.println("Enter amount of symbols per row: ");
symbolsPerLine = input.nextInt();
System.out.println("Amount of symbols per line are: "+ symbolsPerLine);
char [] patternArray = new char[symbolsPerLine];
System.arraycopy(anArray, difSymbols, patternArray, 0, symbolsPerLine);
System.out.print(patternArray);
while(dontStop == 1) {
System.out.print("\n");
printed = 0;
for (int a = 0; a< patternArray.length; a++) {
System.out.print(patternArray[a]);
}
printed++;
}
}
}