我是OCaml的新手(并且仍然是学习编程的新手),我有一个关于检查字符串列表中下一个元素的字符串类型的快速问题.
我希望它在字符串的每个元素之间放置一个分隔符(除了最后一个),但我无法弄清楚如何让程序"知道"最后一个元素是最后一个元素.
这是我现在的代码:
let rec join (separator: string) (l : string list) : string =
begin match l with
| []->""
| head::head2::list-> if head2=[] then head^(join separator list) else head^separator^(join separator list)
end
let test () : bool =
(join "," ["a";"b";"c"]) = "a,b,c"
;; run_test "test_join1" test
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我需要检查一个角色是否是撇号.到目前为止这是我的代码:
public boolean isWordCharacter(int c) {
if ((char) c == '\'')
return true;
else return Character.isLetter(c);
}
Run Code Online (Sandbox Code Playgroud)
然而,它实际上从未进入过这个if ((char) c == '\'')部分.我检查的方式有问题吗?谢谢!
到目前为止这是我的代码:
public static void main(String[] args){
JFrame frame = new JFrame("Breakout!");
frame.setLocation(300, 300);
//Making the menubar
JMenuBar mb = new JMenuBar();
frame.setJMenuBar(mb);
JMenu fileMenu = new JMenu("File");
mb.add(fileMenu);
JMenuItem newAction = new JMenuItem("About");
fileMenu.add(newAction);
newAction.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("open new window here");
}
});
BreakoutCourt c = new BreakoutCourt();
frame.add(c);
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Run Code Online (Sandbox Code Playgroud)
我正在制作突围游戏.我想创建一个关于窗口,显示有关游戏的信息(比如,如何播放等等).我该怎么做呢?感谢您的帮助!我是Java Swing的新手,所以是的.