Kitty and Katty

  • + 1 comment

    In Java modulo operation -1 % 3 = -1 , One of the answer said that -1 % 3 =2 But java doesn't calculate like that. How can find result of 2 in -1 % 3 Here the sample java program I run: class Remainder {

      public static void main (String args[]) {
    
        int i = -1;
        int j = 3;
    
        System.out.println("i is " + i);
        System.out.println("j is " + j);
    
        int k = i % j;
        System.out.println("i%j is " + k);
      }
    
    }