-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathCycleNFromS.java
More file actions
72 lines (63 loc) · 1.58 KB
/
Copy pathCycleNFromS.java
File metadata and controls
72 lines (63 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.util.ArrayList;
import java.util.Scanner;
public class CycleNFromS
{
public CycleNFromS(String from,int times)
{
this.N = times;
this.S = from;
}
public static void main(String[] args)
{
System.out.println("请按先后顺序输入初始值以及循环次数,并以空格隔开");
Scanner scanner = new Scanner(System.in);
String[] data = scanner.nextLine().split(" ");
String from = data[0];
int times = Integer.parseInt(data[1]);
CycleNFromS initObj = new CycleNFromS(from,times);
finalResList = initObj.equipResult(S);
for(String str:finalResList)
{
System.out.print(str + " ");
}
}
public int getStringLength(String sourceStr)
{
return sourceStr.length();
}
public int stringToInteger(String sourceStr)
{
return Integer.parseInt(sourceStr);
}
/**
* @param sourceStr
* @return
*/
public ArrayList<String> equipResult(String sourceStr)
{
int length = sourceStr.length();
Integer indexNum = Integer.parseInt(sourceStr);
ArrayList<String> resList = new ArrayList<String>();
Integer nextNum = 0;
for(int i = 0; i < N;i++)
{
String preResult = "";
nextNum = indexNum + i;
if(nextNum.toString().indexOf("4") >= 0)
{
N++;
continue;
}else{
for(int index = length-indexNum.toString().length();index >0;index--)
{
preResult += "0";
}
resList.add(preResult + nextNum);
}
}
return resList;
}
private static ArrayList<String> finalResList;
private static String S = "000003";
private static int N = 10;
}