我一直在尝试这个int和long转换,我尝试将int变量long赋给变量.代码如下:
public static void main(String []args){
int i = 1024;
long j = i;
long k = i*i*i*i;
System.out.println("j= " +j+ ", k= " +k);
}
Run Code Online (Sandbox Code Playgroud)
因此,在打印时j,它只是给出了输出1024.但是在打印时k,它显示溢出(k= 0).我通过使用这种技术解决了这个问题,我已经明确地将每个问题都转换i为了long.即
public static void main(String []args){
int i = 1024;
long j = i;
long k = ((long)i)*((long)i)*((long)i)*((long)i);
System.out.println("j= " +j+ ", k= " +k);
}
Run Code Online (Sandbox Code Playgroud)
现在,这既表现出的正确的价值观j和k.所以,我想知道为什么需要int在第二种情况下进行投射,而不是在第一种情况下投射.在这个繁重的任务之后k,作为一个long可以保留这个值.但是,为什么没有正确分配?
我是Ocaml编程的完全初学者,我无法将模块链接到我的程序中.实际上我正在做一些正则表达式检查,我编写了一个函数,它基本上使用Str模块基于分隔符字符串标记字符串.所以我使用库中定义的函数,如下所示:
Str.regexp_string /*and so on*/
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试编译ml文件时,我收到一个错误,表明我有一个未定义的全局Str.我们通过键入List.length来使用List函数,就像我为Str做的那样,而不必明确包含特定的模块.我试过了
open Str;;
include Str;; /*None of these work and I still get the same error*/
Run Code Online (Sandbox Code Playgroud)
但是,如果在我使用的顶层
load "str.cma" /*Then the program works without problems*/
Run Code Online (Sandbox Code Playgroud)
我想将模块包含在ml文件中,因为我必须在最后链接3 cmo以获得最终的可执行文件(不在顶层中运行).我知道这是一个非常基本的问题,但我无法解决它.提前致谢.