我正在尝试构建一个响应不同的函数,具体取决于参数是空列表还是包含某些内容的列表.我的代码:
validateCypher :: [Char] -> [Char]
validateCypher [] = cypherB
validateCyper n:[] = ['O']
Run Code Online (Sandbox Code Playgroud)
然而,返回
声明中的语法错误(意外符号":")
想法?:)
假设我有元组列表:
[('X', 3.0), ('B', 0.0), ('N', 4.33)]
Run Code Online (Sandbox Code Playgroud)
我想要一个函数,从第二个元素为0或更低的列表中删除所有元组.我的尝试:
dELS :: [(Char, Float)] -> [(Char, Float)]
dELS x = [c | c <- x, snd x > 0.0]
Run Code Online (Sandbox Code Playgroud)
但那回归......
*** Expression : snd x
*** Term : x
*** Type : [(Char,Float)]
*** Does not match : (a,b)
Run Code Online (Sandbox Code Playgroud)
思考?
我试图让一个方法使用递归,我的方法读取:
public int recursion(int start) {
if(start >= 1)
recursion(start-1);
return start;
}
Run Code Online (Sandbox Code Playgroud)
但是,我收到一个错误,告诉我无法找到方法"递归".有什么建议?:)
干杯!
我有一个Integer类型的ArrayList,是否可以在其中存储一个值(例如:1.25)而不必将其转换为int因此丢失小数后的位?
我有以下代码:
String tmp = "cif";
String control = tmp.substring(1);
if(control == "if") {
append = "if( ";
}
Run Code Online (Sandbox Code Playgroud)
然而,尽管控制是"如果",测试仍然会失败.有解决方案吗
我有以下java代码,它应该在一个套牌中"洗牌".甲板是一个包含卡片对象的arraylist.
private void ShuffleDeck() {
//Number of cards in deck
int deckSize = deck.size();
//Swapping 100 cards
for(int i = 0; i < 15; i++) {
//Generating two random card indexes
int indexA = (int) ((Math.random() * deckSize-1));
int indexB = (int) (Math.random() * deckSize-1);
System.out.println(indexA + " " + indexB);
//Getting objects
Card cardA = deck.get(indexA);
Card cardB = deck.get(indexB);
//Temporaily removing these cards from deck
deck.remove(cardA);
deck.remove(cardB);
//Swapping around the two cards
deck.add(indexA, cardB);
deck.add(indexB, cardA);
}
} …Run Code Online (Sandbox Code Playgroud) 我有以下代码
//Querying for move
int playerMove = currentPlayer.PlayCard(myBoard);
//Making move
try {
playMove(playerMove, currentPlayer);
}
catch (IndexOutOfBoundsException e) {
System.out.println("Sorry, I don't think you can do that...");
}
Run Code Online (Sandbox Code Playgroud)
播放器所做的移动需要与ArrayList中的索引相关联.现在,我的代码偏向于正确进行无效移动的玩家的例外,但我想知道如何修改它以便让玩家继续被移动直到他们成为有效的移动.
谢谢!:)
我试图将以下伪代码转换为Haskell:
stringA = "ABCD"
stringB = "EFGH"
stringC = "ICJK"
function myFunction(String x) {
otherFunction(x)
}
Run Code Online (Sandbox Code Playgroud)
现在,我在哈斯克尔
stringA = "ABCD";
stringB = "EFGH";
stringC = "ICJK";
test :: Int
test x = if x == 1 then otherFunction(??) else ...
Run Code Online (Sandbox Code Playgroud)
当使用x ="stringA"调用test时,如何确保otherFunction将stringA作为参数?
谢谢!:)
我正在编写一个有一个JFrame类和两个JPanel类的接口.首次执行脚本时,将显示Panel A. 我有一个JButton面板A,我想在点击时显示面板B而不是面板A.
有什么方法可以做到这一点吗?
我有一个包含~11,000个元素的python列表e.然后,我有索引列表p〜3000元的.
我想过滤e以仅保留p中指定的索引处的元素.
到目前为止,我正在使用简单的列表理解:
f = [x for i,x in enumerate(e) if i in p]
Run Code Online (Sandbox Code Playgroud)
但是,这种实现需要大约1秒.
这可能不会太多,但由于我必须为10,000个列表执行此操作,因此它将超过2个小时.然后,我必须再次重复这200个批次的10,000个列表,所以它真的太慢了.
知道如何以更快的方式达到相同的结果吗?