levo

Exception Handling and Managing Input and Output

Reading and validating input from the command line

  • 3 things to know
  • AS Unit 1
Start revising · £5/month

Overview

Command line input, range check and presence check.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

How does a Java program read a line typed at the console?

Key term

Why should a prompt be printed before input is read?

Key term

What is the difference between reading a line and reading a number from the console?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is command line input?

    Model answer

    Command line input is data typed by the user at a text prompt while the program is running, read from the standard input stream one value or one line at a time.

  2. 2

    How does a Java program read a line typed at the console?

    Model answer

    A Scanner object is created on System.in, and its nextLine method returns the characters the user typed once the Enter key is pressed.

  3. 3

    Why should a prompt be printed before input is read?

    Model answer

    A program waiting silently for input appears to have stopped, so a prompt tells the user that something is expected and in what form to type it.

  4. 4

    What is the difference between reading a line and reading a number from the console?

    Model answer

    Reading a line returns whatever characters were typed as text, while reading a number asks the input object to convert those characters and fails when they do not form a valid number.

  5. 5

    Why must text read from the console be converted before arithmetic is done on it?

    Model answer

    Characters typed at the keyboard arrive as text, so the digits have to be turned into a numeric type before the program can add, compare or multiply them.

  6. 6

    Which method converts a string of digits into an int in Java?

    Model answer

    The Integer.parseInt method takes a string and returns the whole number those characters represent.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A null is the of one.
absencepresencetype

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Exception Handling and Managing Input and Output, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.