2016-02-22 261 views
1

我在我的第一个编程课上;任何人都可以帮助我理解为什么我不能打印我的最后一行吗?打印一个字符串?

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

     } 

} 

}

+2

搜寻失踪在你的上线“+” – DZDomi

+0

两个查询。第一个 - 为什么你认为这位教授非常糟糕?第二个 - 为什么你认为'只希望我们编码,因为他编码不总是理想的'? –

+0

一。他非常糟糕,因为他试图解释编码技术以及其中不清楚的编码技术。然后他问道是否有意义,当你告诉他时,他并不清楚他指责你这样说:“这很简单,如果你不明白你不应该成为计算机科学专业。”我觉得这很糟糕,因为这是我的第一个计算机科学课。我也相信编码可以用不同的创新方式完成。他明确告诉我们不要按照他告诉我们的方式以任何其他方式执行我们的代码。我认为或相信我们应该探索其他编码选项 –

回答

3

你的最后一行的语法是相当混乱。

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

我终于明白了。谢谢 –

+0

@FarazDurrani是有原因的吗? – intboolstring

+0

@DwightEveridge如果此答案解决了您的问题,您是否可以将其标记为已接受(通过单击复选标记)? – intboolstring

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

您正在使用什么IDE /编辑器?它应该告诉你这里的错误。这应该是

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

这是更好的

+0

我正在使用netBeans –

+1

你应该尝试eclipse。在输入代码时,您将能够看到您的错误。 – qaispak

+0

该课程需要netBeans。除了它,我无法使用其他任何东西。 –