info@meritcampus.com    +91-85006-22255
...
`

Arithmetic Operators1411
What will be the output of the following program?
`public class DayMonthDemo {    public static void main(String args[])     {        int num = 69;        int days = num % 30;        int month = num / 30;        System.out.println(month + " Month and " + days + " days");    }}`

 A. 3 Month and 9 days B. 2 Month and 9 days C. 0 Month and 29 days D. 0 Month and 69 days E. Compilation Error or Runtime Error
Topic:

### User comments below.All of them might not be correct.

B

Posted by Ammad Islam    2015-02-03 09:21:50

b

Posted by Goutham Singarapu    2015-02-03 09:44:16

b.... 2month and 9 days. % operator is used to find the remainder wen two num are divided... here num=69 wen divided by 30 will yield 9 as remainder. hemce days=num%30=9 ....now 69/30 will give 2 as result since this is integral division.... hence month =2 ...

Posted by Asma Mujtaba Khan    2015-02-03 09:44:20

Ans is B.
Here the num stores 69 and we are calculating days using modulo(%) operator on num by 30 which store 9 in 'days' varaible(days = num % 30 = 69 % 30 = 9) and we are calculating months using division(/) operator on num by 30 which stores 2 in 'months' variable(months = num / 30 = 69 / 30 = 2)... which results the output as 2 months and 9 days....

Posted by Gopinath Manchikanti    2015-02-03 09:54:49

ans b . modulus operator, % returns the remainder of a division operation.  when we divide 69(dividend) with 30(divisor) then the quotient is 2 and the modulus (or remainder) is 9.here dividend is sum which is 69, thn remainder assigned with days=9.thn month is assigned with quotient which has value 2.finally sop prints 2 Months and 9 days

Posted by Maheshwari Natarajan    2015-02-03 19:08:15

This dose is now closed and the winners are Asma Mujtaba Khan,  for 'First Correct Comment', Maheshwari Natarajan,  for 'Best Comment' and Maheshwari Natarajan for the 'Popular Comment'. The 'lucky liker' is Sai Ram. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-02-04 04:33:11