What Does “Think Outside of the Box” Mean ?
In the IT Industry one of the most well-worn phrase is a "Thinking Outside of the Box". It's all about creativity and doing the things in Best+ way. Think a situation like below
Question -: In a MCQ questionnaire num of choices for a question can be change, but only one answer can be selected. Think you have all the answers array from MCQ questionnaire.
Calculate how many times one answer choice selected.
Example -: Choice 1 - 3 Times Selected
Choice 2 - 5 Times Selected
Choice 3 - 6 Times Selected
Choice 4 - 8 Times Selected
Think a best way to do this. You can use any no of Arrays and any other but avoid using if conditions and ternary operations.
Calculate how many times one answer choice selected.
Example -: Choice 1 - 3 Times Selected
Choice 2 - 5 Times Selected
Choice 3 - 6 Times Selected
Choice 4 - 8 Times Selected
Think a best way to do this. You can use any no of Arrays and any other but avoid using if conditions and ternary operations.
Answer -:
public static void main(String[] args){
int[] d = new int[]{4,2,3,3,4,4,6,2};
int choises[] = new int[d.length];
for(int i = 0; i<d.length; i++){
choises[d[i]]++;
}
for(int val : choises){
System.out.println(Integer.valueOf(val));
}
}
int[] d = new int[]{4,2,3,3,4,4,6,2};
int choises[] = new int[d.length];
for(int i = 0; i<d.length; i++){
choises[d[i]]++;
}
for(int val : choises){
System.out.println(Integer.valueOf(val));
}
}
Get more from : http://techprogramme.com/
0 comments:
Post a Comment