First of all i had to add the code to get the input from the user, not sure if you have this back somewhere in your program, but for me "console" was undefined. Just a few "standard" things, define i in your for loop and dont bother incrementing it in your loop. The for loop does that for you(no pun intended). Also, throw brackets into your if statement. It saves lines leaving them out, but if you ever have to add something in the future you'll forget them and have all kinds of errors, better to just get in the practice of putting them in but that's your preference. The root problem you are having is that your "i" is an integer and is doing integer division. Which 1/x where x>1 is going to end up as a decimal which in integer division will be a zero. We counteract this by thrown a "(double)" in front of it to cast it as a double and force it to do float division. The code below worked for me and should work for you.
Side thought: you mentioned that your equation is y = 1-1/2+1/3-......................+1/x. If that is so then i think your if statement may be backwards. Make it a "!=" to have the even fractions subtracted instead of the odd ones. Right now it is vise verse.
int x;
double y = 1.0;
Scanner console = new Scanner(System.in);
System.out.print("Please Enter A Number ");
x = console.nextInt();
for (int i = 2; i <= x; i++) {
if ((i % 2) == 0) {
y = y + (1 / (double)i);
} else {
y = y - (1 / (double)i);
}
}
System.out.print("The Result Of Y is " + y);