我试图用正方形填充整个屏幕,每个正方形填充不同的颜色.我能够生成整个正方形的屏幕,但我不能让它们成为随机颜色.这是我到目前为止:
import java.util.Random;
public class RGBRandom
{
public static void main(String[] args)
{
StdDraw.setScale(0, 100);
for (int x = 0; x <= 100; x++)
{
for (int y = 0; y <= 100; y++)
{
int r = (int)Math.random()*256;
int g = (int)Math.random()*256;
int b = (int)Math.random()*256;
StdDraw.setPenColor(r, g, b);
StdDraw.filledSquare(x, y, 0.5);
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我需要从命令行中取出单词,将它们保存到一个数组中,然后打印出如下的单词:
input: asdf jkl qwerty dfs
output: - jkl qwerty dfs
asdf - qwerty dfs
asdf jkl - qwerty dfs
asdf jkl qwerty -
Run Code Online (Sandbox Code Playgroud)
此外,如果用户只提供2个单词,我应该会得到相同的结果.当所给出的论据数量每次都不同时,我不明白我会怎么做.这是我尝试过的:
public static void main(String[] args)
{
String input1 = args[0];
String input2 = args[1];
String input3 = args[2];
String input4 = args[3];
String[] input = new String[4];
}
public static void printExceptOne(String[] exception, int x)
{
System.out.print("-");
System.out.print(" "+exception[1]);
System.out.print(" "+exception[2]);
System.out.println(" "+exception[3]);
}
}
Run Code Online (Sandbox Code Playgroud)