所以我做了使用網絡上的各種片段這段代碼,這樣我可以看到方法它是如何工作的,但由於一些奇怪的原因,第四屆「for」循環被完全忽略,而且我不確定爲什麼。任何幫助,將不勝感激。它是一個使用代碼的命令行。的Java:使用數組變量
public class New1
{
public static void main(String[] args) throws InterruptedException
{
Scanner in = new Scanner(System.in);
System.out.print("Enter number of clicks before repeat: ");
int Clicks = in.nextInt();
int rep2 = 0;
int Waits[] = new int[Clicks];
Clicks = Clicks * 2;
int Coords[] = new int[Clicks];
Clicks = Clicks/2;
int Gung;
int Ho;
int Yo;
int xco = 0;
int yco = 1;
if(Clicks > 0)
{
for (int rep = 0; rep < Coords.length; rep++)
{
System.out.print("Enter x coord: ");
Coords[rep] = in.nextInt();
rep++;
System.out.println(" ");
System.out.print("Enter y coord: ");
Coords[rep] = in.nextInt();
System.out.println(" ");
System.out.print("Enter the pause (In seconds) between this click and the next click: ");
Waits[rep2] = in.nextInt();
rep2++;
System.out.println(" ");
}
rep2 = 0;
for (int rep3 = 0; rep3 < Waits.length; rep3++)
{
Waits[rep3] = Waits[rep3] * 1000;
}
System.out.print("How many times to repeat click sequence? : ");
int Revolutions = in.nextInt();
for (int counter = 0; counter > Revolutions; counter++)
{
for (int Flicks = 0; Flicks > Clicks; Flicks++)
{
Gung = Coords[xco];
Ho = Coords[yco];
Yo = Waits[Flicks];
Click(Gung, Ho);
Thread.sleep(Yo);
xco += 2;
yco += 2;
}
xco = 0;
yco = 1;
}
}
}
public static void Click(int x, int y)
{
Robot bot = null;
try
{
bot = new Robot();
}
catch (Exception failed)
{
System.err.println("Failed instantiating Robot: " + failed);
}
int mask = InputEvent.BUTTON1_DOWN_MASK;
bot.mouseMove(x, y);
bot.mousePress(mask);
bot.mouseRelease(mask);
}
public static void printArray(int arr[])
{
int n = arr.length;
for (int ar = 0; ar < n; ar++)
{
System.out.print(arr[ar] + " ");
}
System.out.println(" ");
}
}
編輯:第四屆 「for」 循環是
for (int Flicks = 0; Flicks > Clicks; Flicks++)
{
Gung = Coords[xco];
Ho = Coords[yco];
Yo = Waits[Flicks];
Click(Gung, Ho);
Thread.sleep(Yo);
xco += 2;
yco += 2;
}
我假設第4個循環在方法printArray()中。那是對的嗎? – Forseth11
第4個for循環是從未調用過的方法。也許你應該從一些教程開始? https://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html – Radiodef
4th for循環實際上是使用Click()方法的,我只使用printArray()來檢出數組看看他們是否工作正常 –