2014-04-16 82 views
1

我開始學習java與deitel書,我正在做他們寫的練習。改變我的java目錄路徑(在打開時)後 我突然開始遇到與印刷方法,如的printf格式的println編譯器顯示我有一個與它的錯誤,但它工作之前,我改變的問題回到路上......開一個新班,還有同樣的問題,有什麼想法?問題與印刷,格式,println - java

此外,沒有人有一個文件或網頁的多個練習與java解決方案的鏈接?

package examples; 


import java.util.Scanner; 
public class exampleOne { 
public static int j=0; 
public static void main (String [] args){ 
    boolean [] seats = new boolean [10]; 
    for(int i=0; i< seats.length; i++) 
     seats[i]=false; 

Scanner clasScanner = new Scanner(System.in); 
char c=' '; 
while (c != '1' || c !='2'){ 
System.out.println("Please choose the class of your choice:\n Press 1 for First class\n Press 2 for Economy\n"); 
String choice = clasScanner.next(); 
c = choice.charAt(0); 
if(c == '1') 
    { 
     System.out.print("you choce First class\n"); 
     while (seats[j]==true && j<5) 
       j++; 
     seats[j]=true; 
     System.out.printf("your seat is numbered %d", j+1); 

     break; 
    } 
if(c == '2') 
    { 
     System.out.print("you choce Eonomy class\n"); 
     break; 
    } 

} 
} 

} 

即使這不會工作:

public class Test { 
public static void main (String [] args) 
{ 
    int i=6; 
    System.out.printf("this is i: %d", i); 
} 
} 

這是我得到的錯誤:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, Date) 
    The method format(String, Object[]) in the type String is not applicable for the arguments (String, int, int, int)  
    at examples.Date.<init>(Date.java:17) 
    at examples.EmployeeTest.main(EmployeeTest.java:6)" 

TNX很多

+2

告訴我們你得到了什麼樣的錯誤,所以我們可以幫助更好 – MichaelDD

+0

線程「main」中的異常java.lang.Error:未解決的編譯問題: \t PrintStream類型中的printf(String,Object [])方法是不適用於參數(字符串,日期) \t方法格式在類型(字符串,對象[])字符串不適用於參數(String,int,int,int) \t at examples.Date。 (Date.java:17) \t at examples.EmployeeTest.main(EmployeeTest.java:6) – user3443891

+0

發佈完整的代碼,包括main()。 – tutak

回答

-1

如果使用IDE,比如Eclipse中我會建議檢查項目構建路徑,並檢查IDE應該突出顯示的編譯錯誤。

如果您沒有使用IDE重新編譯整個項目來檢查是否存在編譯錯誤。 從研究,我已經做了我發現,在大多數情況下,這個錯誤是當使用不同類型的編譯器,你試圖運行具有編譯錯誤的代碼拋出(IDE可能會使用略有不同的一個)或(某些IDE可以讓您運行這樣的代碼)。

要確保問題不是由錯誤的代碼,但環境造成了最好的你可以做的是建立完整的新項目,並複製你的代碼,而來自新項目的運行代碼

編輯:我的第一個答案是不正確的

+0

它的奇怪,因爲一個例子工作之前,另一種是從書,因此多數工作:) – user3443891

+0

發帖鏈接到其他答案本身並不構成一個答案。 – Lix