Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
- C
- C
- Clojure
- Cobol
- C++
- C#
- D
- Dart
- Elixir
- Fortran
- Go
- Go
- Haskell
- JS
- Java
- Java
- Java
- Lisp
- Lua
- Obj-C
- PHP
- Pascal
- Perl
- Python
- Python
- Ruby
- Rust
- Rust
- Rust
- Rust
- Scala
(def n (Integer/parseInt (read-line)))
read-line reads the current value of *in* which defaults to System.in
IDENTIFICATION DIVISION.
PROGRAM-ID. stdin.
PROCEDURE DIVISION.
ACCEPT n
STOP RUN.
String? s = stdin.readLineSync();
int? n = int.tryParse(s ?? "");
n will be null if parsing fails. int.Parse could be used instead if we want to throw an exception when parsing fails.
integer :: n
read (*,*) n
n <- (read :: String -> Int) <$> getContents
const {createInterface} = require('readline')
const rl = createInterface ({
input: process.stdin,
output: process.stdout
})
rl.question('Input an integer: ', response => {
let n = parseInt (response)
// stuff to be done with n goes here
rl.close()
})
This example only works with nodeJS (server-side JS) because browser JS does not have a standard input.
Scanner s = new Scanner(System.in);
int n = parseInt(s.nextLine());
s.close();
(setf n (read-from-string (remove-if-not #'digit-char-p (read-line))))
(setf n (read))
if you don't care if it's explicitly an integer
if you don't care if it's explicitly an integer
n = io.read("n")
scanf("%d",&n);
Precisely same as plain C
read(n);
my $n = <> + 0; # read a line from STDIN, add 0 to convert to int
n = int(input("Input Prompting String: "))
n = int(input())
n = $stdin.gets.to_i
gets is Kernel.gets which may not always be stdin. Here we refer explicitly to stdin.
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let n: i32 = input.trim().parse().unwrap();