日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java调用julia脚本,Julia请求脚本中的用户输入

發布時間:2023/12/19 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java调用julia脚本,Julia请求脚本中的用户输入 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如何從Julia中運行的腳本請求用戶輸入? 在MATLAB中,我會這樣做:

result = input(prompt)

謝謝

最簡單的事情是readline(stdin)。 這就是你要找的東西嗎?

我們可以為此擁有一個更復雜的readline-library-like系統,但是現在這可以解決問題。 Keno的純Julia重新實現我們的repl將為這樣的交互式東西提供一個很好的框架。

在julia 0.7及之后(可能是0.6),現在stdin。

正如@StefanKarpinski所指出的那樣,它將在未來得到解決,這就是我現在所做的:

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>

很好的答案,這有很大幫助。

檢查提供的答案是否與預期類型匹配的函數:

功能定義:

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

函數調用(用法):

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)

總結

以上是生活随笔為你收集整理的java调用julia脚本,Julia请求脚本中的用户输入的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。