如何在每次运行方法时添加循环次数?

时间:2016-01-28 12:07:29

标签: java for-loop

我需要一个循环,在X次停止后循环X次,并循环5次。我怎么能这样做,我做错了什么?

private void loopMethod(anClass someName) {
    int g = 0;
    Random o = new Random();
    int l = 50;
    int a = l + g;
    //System.out.println(g);
    for (int k = 0; k < a; k++) {
        int p = o.nextInt(100);
        if(a == 100){
            k = 101;
        }
        if (p == 1) {
            k = 101;
        } else {

        }
    }
    g = g + 5;
}

1 个答案:

答案 0 :(得分:0)

首先将Sub ProcessFiles() Dim Filename, Pathname, saveFileName As String Dim wb As Workbook Dim initialDisplayAlerts As Boolean Pathname = "" Filename = Dir(Pathname & "*.xlsx") initialDisplayAlerts = Application.DisplayAlerts Application.DisplayAlerts = False Do While Filename <> "" Set wb = Workbooks.Open(Filename:=Pathname & Filename, _ UpdateLinks:=False) wb.CheckCompatibility = False saveFileName = Replace(Filename, ".xlsx", ".xls") wb.SaveAs Filename:=Pathname & saveFileName, _ FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False wb.Close SaveChanges:=False Filename = Dir() Loop Application.DisplayAlerts = initialDisplayAlerts End Sub 声明为全局变量。您可以按如下方式执行此操作:

g

这应该满足您的需求。