import java.util.Scanner;
public class project {
public static void main(String[]args){
Scanner input = new Scanner(System.in);
// to scan the values
int N ;
// numbers of lines
double side1,side2,side3; `
double minimum = 1000;
// to keep the minimum value
double sum = 0;
// to keep calculated values
int which_one = 0 ;
System.out.println("How many triangles do you have?");
N = input.nextInt();
// how many lines
System.out.println("Please, insert lengths of the "
+ "sides of these triangles (3 real numbers per line):");
for (int i = 0; i < N ; i++){
// loop for taking the value from the user
side1 = input.nextDouble(); // input of side1
side2 = input.nextDouble(); // input of side2
side3 = input.nextDouble(); // input of side3
sum = side1 + side2 + side3;
if (sum < minimum ) minimum = sum;
which_one = N+1;
}
System.out.printf("Triangle no."+ which_one
+ " has the minimum perimeter which is %.1f%n "+minimum);
}
}
答案 0 :(得分:1)
您的错误就在这一行。我已经纠正了它应该是什么:
System.out.printf("Triangle no." + which_one +
" has the minimum perimeter which is %.1f\n " , minimum);
我用&#34;&#34;替换+
之前的minimum
。以便minimum
作为格式说明符%.1f
的值提供。