Migration - Strings
There were as many as nine major migrations from mainland Europe into the British isles during the stone age.
The above statement is long and it would be awkward to have to type the phrase more than once in your computer program. So you can use a string variable to save the necessary characters as a value on your computer drive.
To make this statement in Java you can use the code shown below:
- //This code prints a statement about English history.
- class Migration {
- public static void main(String[] args) {
- String migrationstatement;
- migrationstatement = "There were as many as ten major migrations from mainland Europe into the British isles during the stone age.";
- System.out.println(migrationstatement);
- System.out.println();
- System.out.println("Just imagine that!");
- System.out.println();
- System.out.println(migrationstatement);
- }
- }
Use Save As to save the code to your folder as: Migration.java. Then compile the code in the Command prompt window. Use javac Migration.java to create the .class file. Execute the program. Use java Migration to run the program.
Your output should look like this:
c:\javamike>java Migration
There were as many as ten major migrations from mainland Europe into the British Isles during the stone age.
Just imagine that!
There were as many as ten major migrations from mainland Europe into the British Isles during the stone age.