Details

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

Yes. (Although frequently those characters are converted to a numeric type after they have been read in.)

Details

Later on we will do something special to convert strings of digits into primitive numeric types. This program does not do that. Here is the program again:

import java.util.Scanner;

class Echo
{
  public static void main (String[] args)
  {
    String inData;
    Scanner scan = new Scanner( System.in );

    System.out.println("Enter the data:");
    inData = scan.nextLine();

    System.out.println("You entered:" + inData );
  }
}

class Echo

The program defines a class named Echo that contains a single method, its main() method.

public static void main ( String[] args )

All main() methods start this way. Every program should have a main() method.

String inData;

The program will create a String object referred to by the reference variable inData.

Scanner scan = new Scanner( System.in );

This creates a Scanner object, referred to by the reference variable scan.

QUESTION 9:

What data stream is this Scanner connected to?