+ 2
I really need help writing this code !!
This is a java program that calculates the perimeter of triangles and displays the triangle which has the minimum perimeter. It will first ask the user to put how many triangles he has then it asks him to put the 3 sides of each one (each triangle on a line) and finally it will give him the triangle number with the minimum perimiter.
10 Réponses
+ 6
We can't see your code yet. 😐
+ 2
Mike Karam
Post your code here..
Then we help you
+ 1
import java.util.Scanner;
public class Minimum_Perimeter {
public static void main (String[]args) {
Scanner input = new Scanner(System.in);
int n; //No. of triangles input by the user
double min = 1000.0;
int order =0;
System.out.println ("How many triangles do you have?");
n = input.nextInt();
float side1, side2, side3; //Sides of the triangle
float perimeter=0;
System.out.println ("Please, insert lengths of the sides of these triangles (3 real numbers per line): " );
for (int i= 1; i<=n; i++)
{
side1 = input.nextFloat();
side2 = input.nextFloat();
side3 = input.nextFloat();
perimeter = side1 + side2 + side3; //Calculating the perimeter
if (perimeter < min)
min= (double) perimeter;
order++;
System.out.println();
System.out.printf("The minimum perimeter is: %.1f %n" , min);
}
}
+ 1
how many triangles?
example 3
please insert lenghts of the sides...per line.
1 2 3
2 3 4
4 5 6
triangle no.1 has the minimum perimeter wich is 6.0
+ 1
this is the output that i need and im new at this so i could rlly use some help
+ 1
Mike Karam
This help you
https://code.sololearn.com/cjA27jxPMsHU/?ref=app
+ 1
i tried yours it s not working
+ 1
it gives me to lowest perimeter but not the triangle number that has the lowest perimeter
+ 1
but thank you for your help
+ 1
Mike Karam
Its is very easy to print the triangle name..
You can do it.if problem come tell me
I help you