-4
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?

Trojan
  • 2,256
  • 28
  • 40
  • 2
    Hint : `12345 = 823*15+0` – Alexis C. Jan 02 '14 at 09:45
  • 1
    1) Please don't forget to add a '?' to questions! Some people do a search in the page for '?' and if none exists in the 'question' go directly to the next (actual) question in line. 2) Please use code formatting for code, input/output & structured documents like HTML or XML. To do that, select the sample and click the `{}` button above the messaged posting/editing form. – Andrew Thompson Jan 02 '14 at 09:46
  • 3
    what exactly is your question ?... you are getting the right answer (0).. – TheLostMind Jan 02 '14 at 09:47

1 Answers1

4

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

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307