Lifehacks

How do you code an equilateral triangle in Java?

How do you code an equilateral triangle in Java?

JAVA

  1. public class tops.
  2. {
  3. public static void main (String args[])
  4. { float a = 5f ;
  5. double area = ( 1.73 * a*a) / 4 ;
  6. System.out.println(“Area of Equilateral Triangle is:”+area);
  7. }}

How do you draw a triangle in Java?

Draw a Triangle Using drawLine() in Java We call the drawLine() method to draw a line. As we want to create a triangle that three lines, we need to call drawLine() three times. drawLine() takes four arguments, the x and y coordinates of both the first and second points of the line.

How do you draw a triangle in Java with an applet?

Draw Triangle in Java Applet

  1. import java. applet.*;
  2. import java. awt.*;
  3. public class Triangle extends Applet.
  4. {
  5. public void paint(Graphics g1)
  6. {
  7. g1. drawLine(180,150,180,370);
  8. g1. drawLine(180,150,440,370);

How do you find the average of marks in Java?

// java program to find average of marks..

  1. import java. util. Scanner;
  2. public static void main(String args[])
  3. int mark[] = new int[5],i;
  4. float sum=0,avg;
  5. Scanner scan = new Scanner(System. in);
  6. System. out. print(“Enter marks for 5 Subjects : “);
  7. for(i=0; i<5; i++)
  8. mark[i] = scan. nextInt();

How do you find the area of a triangle in Java?

JAVA

  1. public class test.
  2. {
  3. public static void main (String args[])
  4. { float b=4,h =13,area ;
  5. area = ( b*h) / 2 ;
  6. System.out.println(“Area of Triangle is: “+area);
  7. }}

Is there a triangle class in Java?

The class contains: Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle. A no-arg constructor that creates a triangle with specified side1, side2,and side3. The accessor methods for all three data fields.

What are the 5 steps to construct an equilateral triangle?

Steps of construction :

  1. Draw a line segment AB of length 5.5 cm.
  2. Taking 5.5 cm as radius, and A as centre, draw an arc.
  3. Taking 5.5 cm as radius, and B as centre, draw another arc.
  4. Let C be the point where the two arcs intersect . Join AC and BC and label the sides.

How do you draw a shape in Java applet?

To Draw Various Shapes Using Applet In Java Program

  1. import java.awt.*;
  2. import java.applet.*;
  3. public class shap extends Applet.
  4. {
  5. public void paint(Graphics g)
  6. {
  7. g.drawLine(25,25,100,25);
  8. g.drawRect(25,40,100,50);

How do you do percentage in Java?

Percentage = (Obtained score x 100) / Total Score To get these parameters (inputs) from the user, try using the Scanner function in Java.