2016-02-22 263 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。除了它,我無法使用其他任何東西。 –