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