If you want to stay with your int x, you would need to do this:
public static void main(String[] args) {
int buyCost = 4321;
int sellCost = 4252;
int profit = 1000;
int x = (int) (1000 * profit * (sellCost / (double) buyCost));
profit = x / 1000;
System.out.println(profit);
}
Otherwise you are performing an integer division of this part:
(sellCost / buyCost)
which will result in 0, because decimal places are just cut.
See the output of this:
int buyCost = 4321;
int sellCost = 4252;
int x = sellCost / buyCost;
System.out.println(x);
Result: 0
This even happens if your x is of the type double, because the right part is evaluated first. So it performes an integer division and converts the 0 int to a double afterwards.
int buyCost = 4321;
int sellCost = 4252;
double x = sellCost / buyCost;
System.out.println(x);
Result: 0.0
Only this works as you might expect:
int buyCost = 4321;
int sellCost = 4252;
double x = sellCost / (double) buyCost;
System.out.println(x);
Result: 0.984031474195788