道歉,因为我是Java的新手。我刚开始使用方法,所以我不太明白它们是如何工作的。我正在创建一个程序,它将花费标准时间设置的时间(如HH:MM:SS)并将其转换为上午/下午时间(例如,下午2:35)。我已经对程序本身有一些想法,但我的方法存在问题。确切的错误是:“找不到符号”。 EDIT “convertToTraditional(standardTime)”方法发生错误。 这是代码:
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 :(得分:4)
您的方法声明中有一个拼写错误:convertToTradtional
。