Friday, 17 July 2015

Java Programming

Q).Input a hashmap. Count the keys which are not divisible by 4 and return.

  1. package Set1;
  2. import java.util.*;
  3. public class ClassSet47 {
  4.       public static void main(String[] args) {
  5.             Map<Integer, String> m1=new HashMap<Integer, String>();
  6.             m1.put(24, "preethi");
  7.             m1.put(32, "bhanu");
  8.             m1.put(25, "menu");
  9.             m1.put(31, "priya");
  10.             System.out.println(fetchingKeysDivisibleByFour(m1));
  11.       }
  12.       public static int fetchingKeysDivisibleByFour(Map<Integer, String> m1) {
  13.             int k=0;
  14.             Iterator<Integer> i=m1.keySet().iterator();
  15.             loop:
  16.             while(i.hasNext()){
  17.                   int j=i.next();
  18.                   if(j%4!=0)
  19.                         k++;
  20.                   continue loop; }
  21.             return k;
  22.       }
  23. }