+ 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.

10th Apr 2019, 2:53 AM
Mike Karam
Mike Karam - avatar
9 Answers
+ 2
Mike Karam Post your code here.. Then we help you
10th Apr 2019, 4:22 AM
Arun Tomar
Arun Tomar - avatar
+ 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); } }
10th Apr 2019, 6:09 AM
Mike Karam
Mike Karam - avatar
+ 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
10th Apr 2019, 6:14 AM
Mike Karam
Mike Karam - avatar
+ 1
this is the output that i need and im new at this so i could rlly use some help
10th Apr 2019, 6:15 AM
Mike Karam
Mike Karam - avatar
10th Apr 2019, 6:35 AM
Arun Tomar
Arun Tomar - avatar
+ 1
i tried yours it s not working
10th Apr 2019, 11:49 AM
Mike Karam
Mike Karam - avatar
+ 1
it gives me to lowest perimeter but not the triangle number that has the lowest perimeter
10th Apr 2019, 11:51 AM
Mike Karam
Mike Karam - avatar
+ 1
but thank you for your help
10th Apr 2019, 11:53 AM
Mike Karam
Mike Karam - avatar
+ 1
Mike Karam Its is very easy to print the triangle name.. You can do it.if problem come tell me I help you
10th Apr 2019, 12:50 PM
Arun Tomar
Arun Tomar - avatar