java调用julia脚本,Julia请求脚本中的用户输入
如何從Julia中運(yùn)行的腳本請(qǐng)求用戶輸入? 在MATLAB中,我會(huì)這樣做:
result = input(prompt)
謝謝
最簡(jiǎn)單的事情是readline(stdin)。 這就是你要找的東西嗎?
我們可以為此擁有一個(gè)更復(fù)雜的readline-library-like系統(tǒng),但是現(xiàn)在這可以解決問(wèn)題。 Keno的純Julia重新實(shí)現(xiàn)我們的repl將為這樣的交互式東西提供一個(gè)很好的框架。
在julia 0.7及之后(可能是0.6),現(xiàn)在stdin。
正如@StefanKarpinski所指出的那樣,它將在未來(lái)得到解決,這就是我現(xiàn)在所做的:
julia> @doc"""
input(prompt::String="")::String
Read a string from STDIN. The trailing newline is stripped.
The prompt string, if given, is printed to standard output without a
trailing newline before reading input.
""" ->
function input(prompt::String="")::String
print(prompt)
return chomp(readline())
end
input (generic function with 2 methods)
julia> x = parse(Int, input());
42
julia> typeof(ans)
Int64
julia> name = input("What is your name?");
What is your name? Ismael
julia> typeof(name)
String
help?> input
search: input
input(prompt::String="")::String
Read a string from STDIN. The trailing newline is stripped.
The prompt string, if given, is printed to standard output without a trailing newline before reading input.
julia>
很好的答案,這有很大幫助。
檢查提供的答案是否與預(yù)期類(lèi)型匹配的函數(shù):
功能定義:
function getUserInput(T=String,msg="")
print("$msg")
if T == String
return readline()
else
try
return parse(T,readline())
catch
println("Sorry, I could not interpret your answer. Please try again")
getUserInput(T,msg)
end
end
end
函數(shù)調(diào)用(用法):
sentence = getUserInput(String,"Write a sentence:");
n ? ? ? ?= getUserInput(Int64,"Write a number:");
首先,我跑了
Pkg.add("日期")
然后
using Dates
println()
print("enter year "); year = int(readline(STDIN))
print("enter month"); month = int(readline(STDIN))
print("enter day ?"); day = int(readline(STDIN))
date = Date(year, month, day)
println(date)
總結(jié)
以上是生活随笔為你收集整理的java调用julia脚本,Julia请求脚本中的用户输入的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: gta5万圣节脸部彩绘(5能直接玩吗)
- 下一篇: nba2k19安卓版在哪里下(NBA2K