我正在使用Haskell并尝试编写以下内容:
data Scale s = Scale s s
Run Code Online (Sandbox Code Playgroud)
但是,我想使它s必须是Num类型的东西,比如Int或Double.使用Haskell和GHC可以吗?
I am using xmonad and I am unable to get Chromium to display videos in fullscreen.
It was my impression that the following would create a very basic Manage Hook that would detect fullscreen applications and make the window fullscreen and floating:
myManageHook = composeAll [ manageDocks
, manageHook defaultConfig
, (isFullscreen --> doFullFloat) ]
Run Code Online (Sandbox Code Playgroud)
NOTE: This does require xmonad-contrib, which I have. The issue is that a YouTube video in chromium will not fill to fit the entire screen …
我是Java编程的新手,但在浏览了这个网站之后,我相当肯定这应该有用.
public static int[] ArrayStringToArrayInt(String[] arrayString) {
int[] arrayInt = new int[arrayString.length]; //Array of Ints for output
for (int i = 0; i <= arrayString.length; i++ ) { //Run through the
arrayInt[i] = Integer.parseInt(arrayString[i]); //array, Parsing each
} //item into an int
return arrayInt;
}
Run Code Online (Sandbox Code Playgroud)
我想要这个方法做的是获取一个输入数组:["1","2","3"],每个项目都是一个字符串,并返回[1,2,3],其中每个项目都是一个int.
我用这段代码调用方法
int[] toBeSorted = ArrayStringToArrayInt(inputStringArray);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,toBeSorted既在此声明,又在同一时间初始化.
每当我尝试运行它时,我会收到以下错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at sorter.Sorter.ArrayStringToArrayInt(Sorter.java:31)
at sorter.Sorter.main(Sorter.java:22)
Java Result: 1
Run Code Online (Sandbox Code Playgroud)
第31行是我的For循环的主体,是执行解析的部分,第22行是调用方法的地方.
我需要这个的原因是因为我正在尝试使用Scanner类从用户那里获取输入,并希望它们能够同时输入多个数字.然后我使用分隔符模式将输入转换为数组.虽然这看起来很好,但我只能弄清楚如何使输入成为一个字符串数组,而不是整数,这是我的问题.
所以我想我要问的是1)为什么我的代码不起作用?2)是否有更简单的方法从用户获取输入并将其转换为一个int数组?
对于那些想要查看我的整个代码的人来说,就是这样
中间带有测试变量的位和添加两个数字只是我测试代码并查看它是否有效的一种方式.它应该显示在您输入的列表中添加前两个数字的结果
package sorter;
import java.util.Scanner;
import java.util.Arrays;
public class Sorter …Run Code Online (Sandbox Code Playgroud)