Java: 芬奇机器人移动时间

Java: duration of movement of Finch Robot

我是编程新手。我有我的 Finch 机器人的代码,它在用户输入应该循环多少次后简单地循环一个之字形部分,但是我如何输入另一个问题来询问每个之字形部分应该有多长?

例如,我问的第一个问题是用户要循环多少个之字形部分,但我还想问每个之字形部分应该有多长(每条线在转向另一条线之前应该有多长方式)。

代码:

Finch myFinch = new Finch();
Scanner sc = new Scanner(System. in );

System.out.println("Welcome! Complete the following entries");
System.out.println("Number of zigzag sections:  ");

int noOfTimes = sc.nextInt();

do {
    myFinch.setLED(Color.green);
    myFinch.buzz(600, 2250);
    myFinch.setWheelVelocities(180, 0, 750);
    myFinch.setWheelVelocities(100, 100, 1500);
    myFinch.setLED(Color.red);
    myFinch.buzz(600, 2350);
    myFinch.setWheelVelocities(0, 180, 850);
    myFinch.setWheelVelocities(180, 180, 1500);
    noOfTimes--;

} while ( noOfTimes > 0 );

myFinch.quit();
System.exit(0);

检查 java Scanner 文档 here

接受多个输入的代码示例

import java.util.Scanner;

class GetInputFromUser
{
   public static void main(String args[])
   {
      int a;
      float b;
      String s;

      Scanner in = new Scanner(System.in);

      System.out.println("Enter an integer");
      a = in.nextInt();
      System.out.println("You entered integer " + a);

      System.out.println("Enter a float");
      b = in.nextFloat();
      System.out.println("You entered float " + b);  

      System.out.println("Enter a string");
      s = in.nextLine();
      System.out.println("You entered string " + s);
   }
}