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

Welcome with List
What will be the output of the following program?
`import java.util.*;public class Welcome {    public static void main(String[] args) {        int n = 5, k = 3, count = 0;        List<Integer> list = new ArrayList<Integer>();        list.add(10);    list.add(18);        list.add(27);    list.add(34);        list.add(36);    list.add(49);        list.add(56);    list.add(60);        list.add(21);    list.add(45);        list.add(12);    list.add(99);        n = list.size();        for (int i = 0; i < n; i++){            if (list.get(i) % k == 0 && list.get(i) % (k - 1) != 0)                count++;        }        System.out.println("Count is " + count);    }}`

 A. Count is 8 B. Count is 6 C. Count is 4 D. Count is 1 E. Compilation Error or Runtime Error
Topic:

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

option c is the answer since the and operation and the % in the if condition calculation makes the count as 4. the total size is intitally 12math ops makes the count to 4

Posted by Karteek Paruchuri    2013-05-27 12:41:36

Ans is C... as per the logic it should be divisible by 3 n shouldn't divisible by 2.. there are 4 values(27,21,45,99) like that..so count =4

Posted by Krishna Sai    2013-05-27 12:41:59

Ans is C.. becoz for loop accepts only 27,21,45,99 in the list.. so count vl be 4..

Posted by Om Prakash Om    2013-05-27 12:42:09

answer is c : 4 is count as no shld be divide by 3 and not by 2.. numbers are 27 21 99 45

Posted by Pramod Jain    2013-05-27 12:42:58

Congratulations Krishna Sai Mulpuri. You are today's daily dose winner. Please send us your mobile details and we will process the recharge tomorrow after considering the new likes.

Posted by Merit Campus    2013-05-27 14:33:09

Received rc!! thanks :)

Posted by Krishna Sai    2013-05-28 13:58:02

© meritcampus 2019

All Rights Reserved.