Source of TestIntegerDivision.java


  1: //TestIntegerDivision.java
  2: 
  3: public class TestIntegerDivision
  4: {
  5:     public static void main(String args[])
  6:     {
  7:         //Testing integer division (/) and modulus (%)
  8:         //with both positive and negative integers
  9:         System.out.println(-120 / 100);  //Output = -1
 10:         System.out.println(-120 % 100);  //Output = -20
 11:         System.out.println(120 / -100);  //Output = -1
 12:         System.out.println(120 % -100);  //Output = 20
 13:         System.out.println(120 / 100);   //Output = 1
 14:         System.out.println(120 % 100);   //Output = 20
 15:         System.out.println(-120 / -100); //Output = 1
 16:         System.out.println(-120 % -100); //Output = -20
 17:     }
 18: }
 19: