Logo

Programming-Idioms

Read an integer value from the standard input into the variable n
Implementation
Lisp

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Lisp implementation.

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.

Other implementations
import java.util.Scanner;
Scanner in = new Scanner(System.in);
n = in.nextInt();
read(n);
my $n = <> + 0;  # read a line from STDIN, add 0 to convert to int
#include <stdio.h>
int n;
scanf("%d", &n);
#include <iostream>
std::cin >> n;
import std.stdio;
readf("%d", &n);
n <- (read :: String -> Int) <$> getContents
fscanf(STDIN, "%d\n", $n);
import "fmt"
_, err := fmt.Scan(&n)
n = int(input("Input Prompting String: "))
n = $stdin.gets.to_i
n = io.read("n")
fn get_input() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Failed");
    buffer
}

let n = get_input().trim().parse::<i64>().unwrap();
n = String.to_integer IO.gets ""
import "fmt"
_, err := fmt.Scanf("%d", &n)
use std::io;
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let n: i32 = input.trim().parse().unwrap();
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()
})
   integer :: n
   read (*,*) n
using System;
n = int.Parse(Console.ReadLine());
(def n (Integer/parseInt (read-line)))
IDENTIFICATION DIVISION.
PROGRAM-ID. stdin.
PROCEDURE DIVISION.
    ACCEPT n
STOP RUN.
use std::io::BufRead;
let n: i32 = std::io::stdin()
    .lock()
    .lines()
    .next()
    .expect("stdin should be available")
    .expect("couldn't read from stdin")
    .trim()
    .parse()
    .expect("input was not an integer");
#include <stdio.h>
int n[15];
fgets(n, 15, stdin);
scanf("%d",&n);
#[macro_use] extern crate text_io;
let n: i32 = read!();
import 'dart:io';
String? s = stdin.readLineSync();  
int? n = int.tryParse(s ?? "");
import java.util.Scanner;
Scanner in = new Scanner(System.in);
int n = in.nextInt();
import scala.io.StdIn
import scala.util.Try
val n = Try(StdIn.readInt())