Create this echo program and read the explanation.

Here is a Java program.
It reads characters from the keyboard and creates a String object to contain them.
It creates a Scanner object to read from the keyboard. Scanner is a input connection.
The line  import java.util.Scanner;  says to use the Scanner class from the package java.util. Keyboard input was not built into Java so you have to add it in.

   echo code  

Type in the program and test it to see if you can get it to work, then read about how it works and make the changes at the bottom of the page

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 creates 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.

System.out.println("Enter the data:");

This calls the method println to print the characters "Enter the data:" to the monitor.

inData = scan.nextLine();

This uses the nextLine() method of the object referred to by scan to read a line of characters from the keyboard. A String object (referred to by inData) is created to contain the characters.

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

This first creates a String by concatenating "You entered:" to characters from inData, then calls println() to print that String to the monitor.

Change the program so that it will ask for 2 different lines of information, store the information in 2 different string variables and print them out.
NOTE: You do NOT need to create another scanner, use the same scan object each time you read from the keyboard

Enter your name:
Enter the class you are taking:

Then the computer should type out:

Your name is ____ and you are taking the _____ class.