Romans (While)

Map of Britain

The Romans began their invasions into Britain in 55 BCE. Here is a timeline of the occupation.

  1. In 55 BCE Caesar invades but is driven off by the Britons.
  2. In 56 BCE Caesar leads a successful invasion, but the Romans leave.
  3. In 43 CE the Romans invade and occupy Southeastern Britain.
  4. In 60 CE Boudicca leads a rebellion against the Romans.
  5. In 61 CE the Romans defeat Boudicca's rebellion.
  6. By 75 CE the Romans control all of Britain up to the Scottish frontier.
  7. Tribes of Picts and Scotts battle the Romans in the North.

The "While" method continues to loop through the "If Else" conditional statements as long as the "invnumber" variable is less than (<) 8.

This code illustrates the use of a While statement.

  1. import static java.lang.System.out;
  2. public class Romans {
  3. public static void main(String[] args) {
  4. String firstevent = "In 55 BCE Caesar invades but is driven off by the Britons.";
  5. String secondevent = "In 56 BCE Caesar leads a successful invasion, but the Romans leave.";
  6. String thirdevent = "In 43 CE the Romans invade and occupy Southeastern Britain.";
  7. String fourthevent = "In 60 CE Boudicca leads a rebellion against the Romans.";
  8. String fifthevent = "In 61 CE the Romans defeat Boudicca's rebellion.";
  9. String sixthevent = "By 75 CE the Romans control all of Britain up to the Scottish frontier.";
  10. String seventhevent = "Tribes of Picts and Scotts battle the the Romans in the North.";
  11. int invnumber = 0;
  12. while (invnumber < 8) {
  13. invnumber = invnumber + 1;
  14. if (invnumber == 1) {
  15. out.println();
  16. out.println(firstevent);
  17. }
  18. else if (invnumber == 2) {
  19. out.println();
  20. out.println(secondevent);
  21. }
  22. else if (invnumber == 3) {
  23. out.println();
  24. out.println(thirdevent);
  25. }
  26. else if (invnumber == 4) {
  27. out.println();
  28. out.println(fourthevent);
  29. }
  30. else if (invnumber == 5) {
  31. out.println();
  32. out.println(fifthevent);
  33. }
  34. else if (invnumber == 6) {
  35. out.println();
  36. out.println(sixthevent);
  37. }
  38. else if (invnumber == 7) {
  39. out.println();
  40. out.println(seventhevent);
  41. }
  42. else {
  43. out.println();
  44. out.println("End of list.");
  45. }
  46. }
  47. }
  48. }

Java code

Use Save As to save the code to your folder as: Romans.java. Then compile the code in the Command prompt window. Use javac Romans.java to create the .class file. Execute the program. Use java Romans to run the program.

Your output should look like this:

c:\javamike>java Romans

In 55 BCE Caesar invades but is driven off by the Britons.

In 56 BCE Caesar leads a successful invasion, but the Romans leave.

In 43 CE the Romans invade and occupy Southeastern Britain.

In 60 CE Boudicca leads a rebellion against the Romans.

In 61 CE the Romans defeat Boudicca's rebellion.

By 75 CE the Romans control all of Britain up to the Scottish frontier.

Tribes of Picts and Scotts battle the Romans in the North.

End of list.

< Switch (Case) Centuries (For) >