gpt4 book ai didi

Java:使用数组变量的方法

转载 作者:行者123 更新时间:2023-11-30 08:10:32 26 4
gpt4 key购买 nike

所以我使用网络上的各种片段编写了这段代码,以便我可以看到它是如何工作的,但是由于某种奇怪的原因,第四个“For”循环被完全跳过,我不确定为什么。任何帮助,将不胜感激。这是使用代码的命令行。

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;
}

最佳答案

第四个 for 循环是:

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(" ");
}

正如您所看到的,它位于一个名为 printArray() 的方法内。数组没有任何问题。没关系。问题是该方法永远不会被调用,因此 for 循环永远不会运行。

这是一个java methods tutorial .

关于Java:使用数组变量的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30446972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com