所以我试图测试是否有回文.这是我的代码:
此函数返回较大字符串的前半部分的字符串.("TEST"返回"TE","HELLO"返回"HE")
def takeStart(s):
start = ""
# The following determines the final index of the first half
if len(s)%2==0:
a = (len(s)/2)-1
else:
a = ((len(s)-1)/2)-1
for i in range(a):
start+=s[i]
return start
Run Code Online (Sandbox Code Playgroud)
此函数返回较大字符串后半部分的字符串.("TEST"返回"ST","HELLO"返回"LO")
def takeEnd(s):
end = ""
# The following determines the beginning index of the second half
if len(s)%2==0:
a = (len(s)/2)
else:
a = ((len(s)-1)/2)
for i in range(a,len(s)):
end+=s[i]
return end
Run Code Online (Sandbox Code Playgroud)
此函数翻转一个字符串.("TEST"返回"TSET","HELLO"返回"OLLEH")
def flip(s):
flipped = ""
for i in range(1,len(s)):
flipped+=s[len(s)-i]
flipped+=s[0]
return …Run Code Online (Sandbox Code Playgroud) 所以我收到了错误 Class is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
我知道这个错误的起源,但令我困惑的是我有这种方法.
public static ActionListener taskPerformer = new ActionListener(){
public void actionPerformed(ActionEvent e){
Clock cl = new Clock();
if(seconds<59){
seconds++;
}else{
seconds=0;
if(minutes<59){
minutes++;
}else{
minutes=0;
if(hours<12){
hours++;
}else{
hours=0;
}
}
}
cl.repaint();
}
};'
Run Code Online (Sandbox Code Playgroud)
不太确定发生了什么.有帮助吗?提前致谢.
编辑:上下文包括导入和相关方法
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Object.*;
import java.text.DecimalFormat;
import java.awt.geom.*;
public class Clock extends JFrame implements ActionListener{
public static int seconds = 0;
public static int minutes …Run Code Online (Sandbox Code Playgroud)