Print diamond shape in Java
After reviewing your code, I'll point out that:

It would be better if you used more descriptive variable names. It improves readability and might even help you better understand your own code, ex:

int width = sc.nextInt(); // or whatever it represents


Always use curly braces for if and for statements, even if they wrap around a single statement. Shorter code isn't faster, but makes it easier to introduce bugs. You never pay a penalty for extra curly braces or parentheses, so use them as much as you want to clarify intention. For example this snippet can be ambiguous:

for (int i = 0 ; i&lt; y ;i++)
    System.out.print("*");
w=w+1;
y=y-2;


Did you mean

for (int i = 0 ; i&lt; y ;i++) {
    System.out.print("*");
    w=w+1;
    y=y-2;
}


or

for (int i = 0 ; i&lt; y ;i++) {
    System.out.print("*");
}
w=w+1;
y=y-2;