我怎样才能改变一个字符串输入到整型 的示例 -如何改变字符串到整数
read_line_to_codes(user_input,L),
atom_codes(C,L).
在这种C
被存储string.Suppose用户输入18
。所以我想用这个18
作为一个整数,以便我可以使用像>=
和C
这样的操作。这在Prolog中可能吗?
我怎样才能改变一个字符串输入到整型 的示例 -如何改变字符串到整数
read_line_to_codes(user_input,L),
atom_codes(C,L).
在这种C
被存储string.Suppose用户输入18
。所以我想用这个18
作为一个整数,以便我可以使用像>=
和C
这样的操作。这在Prolog中可能吗?
Prolog数据类型不包含“字符串”。 SWI-Prolog的最近添加,但你可以留在ISO安全通道与number_codes
可以强制分配一个int数据类型的用户输入,你让JVM知道,你知道你在做什么,这会让如果int数据类型小于用户输入字符串大小,程序将进行编译。这里是一个示例代码来帮助你。
public class stringToInt{
public static void main(String []args){
string C = 18; //User input, make sure to use the scanner class to get the user input value
int int_C = (int) C;
/**Your new value is now in int datatype and you can go ahead and use int_C for your arithmetic
opreation **/
}
}
的可能的复制[序言:如何将字符串转换为整数(https://stackoverflow.com/questions/6782007/prolog-how-to-convert-string-to-integer) – 2018-02-22 03:12:20