2016-10-24 20 views
0

我是一名開始的程序員,對於我最近在嘗試製作程序時遇到的錯誤感到困惑。我正在嘗試創建一個名爲EasyFormat的課程來安排我的輸出。但是,我遇到一個錯誤,指出:EasyFormat.format錯誤

cannot find symbol - method format(java.lang.String,int). 

我在做什麼嚴重的混亂,我不知道是什麼,我做錯了。如果有人能幫助我,我會非常感激。下面是我的程序是什麼樣子:

public class EasyFormat 
{ 
    public static void main(String args[]) 
    { 
     int x = 0; int space; 
     space = Math.abs((20 - (2 * x))); 

     for(x = 0; x <= 21; x++) 
     { 
      if(x != 11) 
      { 
       System.out.println(EasyFormat.format("X",x)+EasyFormat.format("X",space)); 
      } 
      else 
      { 
      System.out.printf("%11s", "X"); 
      } 
     } 
    } 
} 
+1

我的猜測是,你沒有包括'EasyFormat'相應的庫當你建立你的代碼。 –

回答

0

你有沒有在你EasyFormat類中創建方法format()。因此,您應該先創建方法如下:

private static int format(String string, int x) { 
    // code for proper arrange output 
    return 0; 
} 

我認爲這樣會起作用。

0

嘗試這個

public class EasyFormat{ 

public static void main(String args[]) 
{ 
    int x = 0; int space; 
    space = Math.abs((20 - (2 * x))); 

    for(x = 0; x <= 21; x++) 
    { 
     if(x != 11) 
     { 
     System.out.println(String.format("X",x)+String.format("X",space)); 
     } 
     else 
     { 
     System.out.printf("%11s", "X"); 
     } 
    } 
} 

}