gpt4 book ai didi

java - 我是编程新手,需要将以下输入存储在一个数组中。有什么建议么?

转载 作者:太空宇宙 更新时间:2023-11-04 15:08:55 25 4
gpt4 key购买 nike

下面是我正在使用的代码。我只需要将输入存储在数组中,但我很迷失!

package Code.simpleInput;
import edu.cmu.ri.createlab.terk.robot.finch.Finch;
import java.util.Scanner;

public class LEDSetter
{
private static Scanner sc;

public static void main(final String[] args)
{
// Instantiating the Finch object
Finch myFinch = new Finch();
sc = new Scanner(System.in);

// Providing instructions to the user

System.out.println("Enter the red, green, and blue intensity for the LED (values from 0 to 255)");

// Reading in the three integers
System.out.print("Red: <=200 ");
int red = sc.nextInt();
System.out.print("Green: <=250 ");
int green = sc.nextInt();
System.out.print("Blue: <=250 ");
int blue = sc.nextInt();

/* Potential improvement here - check the user input to make sure that it is in range (0-255) */

// Setting the LED

System.out.println("Thanks, the beak will now glow for 8 seconds according to your specifications");

myFinch.setLED(red,green,blue);
myFinch.sleep(8000);

// Always end your program with finch.quit()

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

最佳答案

如果数组中有三个 int 值,那么

int[] inputs = new int[3];
...
...
sc = new Scanner(System.in);
// Providing instructions to the user
System.out.println("Enter the red, green, and blue intensity for the LED (values from 0 to 255)");
// Reading in the three integers
System.out.print("Red: <=200 ");
int red = sc.nextInt();
inputs[0] = red;
System.out.print("Green: <=250 ");
int green = sc.nextInt();
inputs[1] = green;
System.out.print("Blue: <=250 ");
int blue = sc.nextInt();
inputs[2] = blue;

希望这有帮助!

关于java - 我是编程新手,需要将以下输入存储在一个数组中。有什么建议么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21594229/

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