Dwight Everidge
Dwight Everidge

Reputation: 23

Printing a string?

I'm in my first programming class; can anyone help me understand why I can't print my last line please?

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 + ");

        }

}

}

Upvotes: 1

Views: 990

Answers (2)

intboolstring
intboolstring

Reputation: 7100

Your last line syntax is pretty messed up.

this

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

should be

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

Upvotes: 3

chickenman
chickenman

Reputation: 798

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

What IDE/editor are you using? It should should show you the errors here. This should be

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

This is better

Upvotes: 2

Related Questions