2014-11-22 65 views
1

道歉,因爲我是Java新手。我剛開始使用方法,所以我不太瞭解它們的工作方式。我正在創建一個需要標準時間(如HH:MM:SS)的程序,並將其轉換爲am/pm時間(例如2:35 pm)。我對程序本身已經有了一些想法,但是我的方法有問題。確切的錯誤是:「找不到符號」。 編輯錯誤發生在「convertToTraditional(standardTime)」方法上。 下面是代碼:爲什麼Java不能找到一個方法?

package standardtime; 

/** 
* 
* @author Owner 
*/ 
import java.io.InputStreamReader; 
import java.io.BufferedReader; 
import java.io.IOException; 

public class StandardTime 
{ 
    static String amPM;//will hold am/pm for standard time 
    static String traditionalTime;//will store traditional time from user 
    static int mins1, mins2, hours;//will store hours and minutes 

    public static void main (String args []) throws IOException 
{BufferedReader br = new BufferedReader (new InputStreamReader (System.in));// user input 

    int tryAgain=1;//will initial do-while loop 
    System.out.println("Standard Time to Traditional Time Converter"); 
    System.out.println("==========================================="); 
    do{ 
    System.out.println(); 
    System.out.println("Input a time in Standard Form (HH:MM:SS):"); 
    String standardTime=br.readLine();//user inputs time in standard form 
    System.out.println(); 



    do{ 
    if ((standardTime.length())!=8){ 
    System.out.println("Invalid time entered."); 
    System.out.println("Input a time in Standard Form that has this form HH:MM:SS ..."); 
    standardTime=br.readLine();//user inputs time in standard form 
    System.out.println(); 
    } 
    }while((standardTime.length())!=8); 
    //method declaration 
    convertToTraditional(standardTime); // call the coversion method 



    System.out.println(standardTime+" is equivalent to "+traditionalTime); 
    System.out.println(); 
    System.out.println("Enter 1 to try again."); 
    tryAgain=Integer.parseInt(br.readLine());//user decides to try again 
    }while(tryAgain==1);//will repeat if user enters 1 

}//closes main body 
    public static void convertToTradtional(String standardTime) 
    { 
    String hour = standardTime.substring(0,1); 
    hours = Integer.parseInt(hour); 
    int hourNormal = hours - 12; 
    Integer.toString(hourNormal); 
    String minutes = standardTime.substring(3,4); 
    traditionalTime = hourNormal + minutes; 

    } 


} 
+0

對不起。我編輯了我原來的帖子。它沒有找到「convertToTraditional(standardTime);」 – 2014-11-22 13:50:33

回答

4

你有一個錯字在你的方法聲明:convertToTradtional

相關問題