Dart is a client optimized programming language that can be used for apps on multiple platforms. It is based on object oriented programming and it can be compiled to JavaScript or native code.
To take input from a user in Dart, you need to import the dart:io
library. The input is taken through the console
using the .readLineSync()
function.
In the code below, enter your name in stdin
column first and then press the run button:
import 'dart:io';void main(){String name = stdin.readLineSync();print("Hello, $name");}
Enter the input below
This was how you can take a string as input in the console. Below, we will see how we can take an integer value as input in the console:
import 'dart:io';void main(){int number = int.parse(stdin.readLineSync());print("The number is $number");}
Enter the input below