Migration - Strings

Beach at sunset

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:

    1. //This code prints a statement about English history.
    2. class Migration {
    3. public static void main(String[] args) {
    4. String migrationstatement;
    5. migrationstatement = "There were as many as ten major migrations from mainland Europe into the British isles during the stone age.";
    6. System.out.println(migrationstatement);
    7. System.out.println();
    8. System.out.println("Just imagine that!");
    9. System.out.println();
    10. System.out.println(migrationstatement);
    11. }
    12. }

 

Java code

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.

 

< Beginnings Tribes (Int) >