Text Size
Thursday, January 27, 2022

Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/cmwhittington/theteach.ca/components/com_komento/helpers/string.php on line 327

Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/cmwhittington/theteach.ca/components/com_komento/helpers/string.php on line 329

Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/cmwhittington/theteach.ca/components/com_komento/helpers/string.php on line 330

Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/cmwhittington/theteach.ca/components/com_komento/helpers/string.php on line 331

Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/cmwhittington/theteach.ca/libraries/gantry/core/utilities/registry/format/ini.php on line 107

Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/cmwhittington/theteach.ca/libraries/gantry/core/utilities/registry/format/ini.php on line 120

Content

Input from the Console

Introduction
In java reading input from the console can be a bit difficult for the beginner to understand. Reading from the console includes some concepts that the beginner should not worry to much about understanding.

Objects
There are two data type (objects) that are needed to efficiently read information from the console.
The first is called InputStreamReader. The InputStreamReader is capable of reading data from the console.
The second is called BufferedReader. This object makes the InputStreamReader work more efficiently.

Code
InputStreamReader isr=new InputStreamReader(System.in);
This line creates an InputStreamReader called isr. This reader looks at input from the System.in stream. System.in is input from the console.

BufferedReader br=new BufferedReader(isr);
Next we create a BufferedReader named br. br is a reader for isr. This gets a little confusing but think of br as a translator for isr.

String input=br.readLine();
Next we create a String called input. br.readLine() gets input from the console and input is set equal to whatever br reads.

Download the complete code here.

Leave your comments

0
terms and condition.
  • No comments found
Parent Category: ICS4U