In the code below, when x = 60 and y = 2, result = 500. This is correct, but any x value between 60 and 119 also gives 500. Also, when x < 60, I get a divide by 0 error. Additionally, when x >= 120, result = 0. I am stumped as to why this is happening. I have also tried using various combinations of int, float, and long and still, no luck.
public class main {
static long result;
static int x;
static int y;
public static void main(String[] args) {
x = 60;
y = 2;
result = 1000 * (1 / (x / 60)) / y;
System.out.println(result);
}
}
By the way, I encountered this problem while trying to make a metronome application for Android. I took this code out of context to make it easier to isolate the problem. Any help and/or suggestions are very appreciated!