1

Javaで特定の座標で三角形を描こうとしています。一応描いたけど問題あり。出力とコードをそこに置きます。ご覧のとおり、三角形の辺が長すぎるので、それらを制限する必要があります。皆さん、これで私を助けてくれませんか?

ここに画像の説明を入力

System.out.print("For triangle, we need the coordinates of the points for three vertices. \nPlease enter the coordinates of 3 vertices a, b, c, d, e, f:-5 2 0 6 5 2 \n");
        

a=input.nextInt();

int b=input.nextInt();

int c=input.nextInt();
int d=input.nextInt();
int e=input.nextInt();
int f=input.nextInt();
for (int y = 10; y >= -11; y--) {
    for (int x = -10; x <= 11; x++) {
    
    if(y==0) {              
        if(((x-c)*(d-b)/(c-a)+d==0)||((x-e)*(f-d)/(e-c)+f==0)||(x-a)*(b-f)/(a-e)+b==0)  
            System.out.print("*");   
            else if(x==0)
                System.out.print("|");
            else if(x==11)
                System.out.print("x");
            else
                System.out.print("-");
        }
    else if(((x-c)*(d-b)/(c-a)+d==y)||((x-e)*(f-d)/(e-c)+f==y)||(x-a)*(b-f)/(a-e)+b==y)              
        System.out.print("*"); 
        else if(x==0) {
            if(y==10)
                System.out.print("y");
            else
                System.out.print("|");
        }
        else
            System.out.print(" ");
    }
    System.out.println("");    
}          
4

0 に答える 0