首页 > 解决方案 > 为什么不将这些东西用作颜色并用它来决定颜色?

问题描述

//我试图让它采用我为颜色创建的方法,以便它可以创建不同的红色阴影

导入 java.util.Scanner;公共类流行音乐{

public static void main(String[] args) throws java.io.IOException {
    StdDraw.enableDoubleBuffering();
    java.util.Scanner scan = new java.util.Scanner(new java.io.FileReader("numfile.txt"));
    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();

    //asks user for input to choose colors
    Scanner myObj = new Scanner(System.in);
    System.out.println("Enter a number between 1 and 10");
    int number = myObj.nextInt();  // Read user input
    System.out.println("The number you selected is " + number + ". Good choice! One moment...");
    //creates new variables by multiplying the input number and file numbers


        StdDraw.enableDoubleBuffering();
        rerectangle(0.0, 0.5);
        color(a*number);
        StdDraw.show();
    }

static void rerectangle(double x, double radius) {
    if (radius > 0.01) {
        StdDraw.setPenColor(color(), 0, 0);
        StdDraw.filledRectangle(0.5, radius, radius, radius);
        rerectangle(x + radius * 0.2, radius * 0.9);
    }
}

static int color(int color1) {
    return (color1 * 2);
}

}

标签: javarecursioncolors

解决方案


推荐阅读