Compiling
Before you follow the instructions below, make sure you have this class in a working directory on Eclipse:
public class OddEven {
public static boolean isEven(int n) {
return n % 2 == 0;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int number = Integer.valueOf(args[0]);
if (isEven(number)) {
System.out.println("Even");
} else {
System.out.println("Odd");
}
}
}
- Download the JDK Development Kit
- Open a local terminal (that can be done in several ways, on Eclipse go to
Window
>Show View
>Terminal
) - Here’s what my terminal looks like:
- Change directory (cd) into your project folder (my working directory is in a folder called CSC210 on my Desktop):
- cd into the src folder:
cd src
- We will compile our
.java
file first by enteringjavac OddEven.java
into our local terminal - To run our binary code with an argument we can enter
java OddEven 2