我正在尝试编写一个函数,该函数对每行提供的整数求和,并在输入0时停止.到目前为止我有这个:
getInt :: IO Int
getInt = do
s <- getLine
return (read s)
sumInts :: IO Int
sumInts = do
x<-getInt
if x==0 then return 0 else return (x+sumInts)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试运行它时出现错误:
无法将预期类型Int与实际类型IO Int匹配
我想编写一个函数,接受一个数字i和号码的列表xs,并返回位置的i列表中xs,数为1的第一个位置.如果i不发生xs,则position返回0.
到目前为止我有这个:
import Data.List
position :: Int -> [Int] -> Int
position i xs
| i `elem` xs = i `elemIndex` xs
| otherwise = 0
Run Code Online (Sandbox Code Playgroud)
但是当我编译时,它会给出以下错误:
无法将预期类型'Int'与实际类型'Maybe Int'匹配
我知道elemIndex返回一个Maybe Int类型,我定义了我的函数返回Int但我不知道如何更改它.有任何想法吗?
我想编写一个简单的程序,从键盘读取数组并将其粘贴到屏幕上.当我编译它时,我收到以下错误:
Keyboard cannot be resolved
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import java.util.*;
import java.io.*;
public class Test2
{
public static void main (String args[])
{
int i, n;
int[] myList= new int[100];
System.out.println ("n= "); Keyboard.getInt(n);
for (i=1; i<=n; i++)
{
System.out.println ("myList[" + i + "]= ");
Keyboard.getInt(myList[i]);
}
for (i=1; i<=n; i++)
System.out.println (myList[i]);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Eclipse Luna.我是否需要下载任何软件包才能使用Keyboard.getInt功能?谢谢!
我有以下 xml 资源代码,它是卡片项目列表的背景布局
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#CABBBBBB"/>
<corners android:radius="2dp" />
</shape>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="2dp"
android:drawable="@drawable/kpop">
<shape android:shape="rectangle">
<solid android:color="#151B54"/>
<corners android:radius="2dp" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我的问题是我想以编程方式更改可绘制资源
android:drawable="@drawable/kpop"
Run Code Online (Sandbox Code Playgroud)
(这样每个卡片项目都会有不同的背景图像)
任何想法/提示我怎么能做到这一点?