This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
- 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
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.
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();
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let n: i32 = input.trim().parse().unwrap();
programming-idioms.org