How do you code an equilateral triangle in Java?
How do you code an equilateral triangle in Java?
JAVA
- public class tops.
- {
- public static void main (String args[])
- { float a = 5f ;
- double area = ( 1.73 * a*a) / 4 ;
- System.out.println(“Area of Equilateral Triangle is:”+area);
- }}
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
- import java. applet.*;
- import java. awt.*;
- public class Triangle extends Applet.
- {
- public void paint(Graphics g1)
- {
- g1. drawLine(180,150,180,370);
- g1. drawLine(180,150,440,370);
How do you find the average of marks in Java?
// java program to find average of marks..
- import java. util. Scanner;
- public static void main(String args[])
- int mark[] = new int[5],i;
- float sum=0,avg;
- Scanner scan = new Scanner(System. in);
- System. out. print(“Enter marks for 5 Subjects : “);
- for(i=0; i<5; i++)
- mark[i] = scan. nextInt();
How do you find the area of a triangle in Java?
JAVA
- public class test.
- {
- public static void main (String args[])
- { float b=4,h =13,area ;
- area = ( b*h) / 2 ;
- System.out.println(“Area of Triangle is: “+area);
- }}
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 :
- Draw a line segment AB of length 5.5 cm.
- Taking 5.5 cm as radius, and A as centre, draw an arc.
- Taking 5.5 cm as radius, and B as centre, draw another arc.
- 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
- import java.awt.*;
- import java.applet.*;
- public class shap extends Applet.
- {
- public void paint(Graphics g)
- {
- g.drawLine(25,25,100,25);
- 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.