This is just a little reminder on how Java code looks like and how it is compiled and executed. I’m running OS X 10.10 and I have the Java for OS X 2014-001 package installed — not sure if this is necessary.
1. Write a Program
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
public class HelloWorld { public static void main (String[] args) { // Variables int n = 5; String line = "Hello World"; // Loop for (int i=1; i<=n; i++) { // Condition if (i % 2 == 0) { // Output if number is even System.out.println(i + ". " + line + " (even)"); } else { // Output if number is uneven System.out.println(i + ". " + line + " (uneven)"); } } } } |
Save this as HelloWorld.java
2. Compile It
1 |
javac HelloWorld.java |
A HelloWorld.class will be created
3. Run It
1 |
java HelloWorld |
Leave a Comment