public class Triangle {
public static void main(String[] args) {
int n=12345, x=15;
int res =(n % x);
System.out.println(res);
}
}
The statement int res = (n%x)
is 0
. Why?
public class Triangle {
public static void main(String[] args) {
int n=12345, x=15;
int res =(n % x);
System.out.println(res);
}
}
The statement int res = (n%x)
is 0
. Why?
When you do,
12345/15
It exactly divides it by 823 times and reminder is zero.
There is nothing wrong it with %. Make sure that you want reminder or the result of n/x