打印字符串?

德怀特·埃夫里奇

我在我的第一门编程课上。谁能帮助我理解为什么我不能打印我的最后一行?

package program4;

import java.util.*;

public class Program4 {

    public static void main(String[] args) {
        int a, b, c, numComparisons;

        String comparisons = "Comparisons for triangleType determination: ";
        Scanner scan = new Scanner(System.in);
        for (int i = 0; i < 7; i++) {
        }
        String triangleType = "";
        System.out.print("Enter 3 positive integer lengths for the sides of a "
                + "triangle:");
        a = scan.nextInt();
        b = scan.nextInt();
        c = scan.nextInt();

        System.out.println("The input lengths are: a = " + a + ", b = " + b + ", and"
                + " c = " + c + "");

        if ((a + b < c) || (b + c < a) || (a + c < b)) {

            System.out.print("There is no triangle with sides " + a + ", " + b + " and "
                    + "" + c + ".");
        } else {
            numComparisons = 1;
            comparisons += "a==b";
            if (a == b) {
                comparisons += "(T)" + "(b==c)";
                numComparisons++;
                if (b == c) {
                    comparisons += "(T)";
                    triangleType = "Equilateral";
                }
            } else {
                comparisons += "(F)";
                if (a == c) {
                    comparisons += "(T)";
                    triangleType = "Isosceles";
                } else {
                    comparisons += "b==c";
                    numComparisons++;
                    comparisons += "(F)";

                    if (b == c) {
                        triangleType = "Isosceles";
                    } else {
                        comparisons += "a==c";
                        numComparisons++;
                        comparisons += "(F)";
                        triangleType = "Scalene";
                    }
                }

            }
            System.out.printf("" + comparisons + (""));
            System.out.printf("numComparisons = " + numComparisons);
            System.out.println("The triangles with sides " + a + ", "
                    + " + b + ", and " + c + ", is + triangleType + ");

        }

}

}

内弦

您的最后一行语法非常混乱。

 System.out.println("The triangles with sides " + a + ", "
                    + " + b + ", and " + c + ", is + triangleType + ");

应该

 System.out.println("The triangles with sides " + a + ", "
                    +  b + ", and " + c + ", is " + triangleType);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章