Question 6:
Write a program in Java to find the perimeter of a triangle using Assignment
Statement.
Answers
Answered by
0
Answer:
import java.util.Scanner;
public class Perimeter
{
int r, l, b, s1, s2, s3;
double pi = 3.14,perimeter;
Scanner s = new Scanner(System.in);
void triangle()
{
System.out.print("Enter length of first side of triangle:");
s1 = s.nextInt();
System.out.print("Enter length of second side of triangle:");
s2 = s.nextInt();
System.out.print("Enter length of third side of triangle:");
s3 = s.nextInt();
perimeter = s1 + s2 + s3;
System.out.println("Perimeter of triangle:"+perimeter);
}
Output:
$ javac Perimeter.java
$ java Perimeter
Enter length of first side of triangle:3
Enter length of second side of triangle:4
Enter length of third side of triangle:5
Perimeter of triangle:12.0
Similar questions