User input/Text: Difference between revisions
Content deleted Content added
Added R code |
→{{header|Haskell}}: As written, this solution was incorrect, since it would sometimes only print the prompts after the input had been received. |
||
Line 256: | Line 256: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<lang haskell> |
<lang haskell> |
||
import System.IO (hFlush, stdout) |
|||
main = do |
|||
putStr "Enter a string: " |
putStr "Enter a string: " |
||
hFlush stdout |
|||
str <- getLine |
str <- getLine |
||
putStr "Enter an integer: " |
putStr "Enter an integer: " |
||
hFlush stdout |
|||
num <- readLn :: IO Int |
num <- readLn :: IO Int |
||
putStrLn $ str ++ (show num)</lang> |
putStrLn $ str ++ (show num)</lang> |
||
Note: <tt>:: IO Int</tt> is only there to disambiguate what type we wanted from <tt>read</tt>. If <tt>num</tt> were used in a numerical context, its type would have been inferred by the interpreter/compiler. |
Note: <tt>:: IO Int</tt> is only there to disambiguate what type we wanted from <tt>read</tt>. If <tt>num</tt> were used in a numerical context, its type would have been inferred by the interpreter/compiler. |
||
Note also: Haskell doesn't automatically flush stdout when doing input, so explicit flushes are necessary. |
|||
=={{header|Java}}== |
=={{header|Java}}== |