1

I have been trying to draw triangle by specific coordinates on java. I kinda drew it but there is a problem. I put the output and my code down there. As you can see, sides of the triangle are too long, I need to limit them. Can you guys help me out with this, maybe give me some idea?

enter image description here

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("");    
}          
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214

0 Answers0