Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi here is my code let me am I correct or not?
Thanks in advance.

package com.cnu.ds;

import java.util.ArrayList;
import java.util.List;

public class Combinations {
	public static void main(String[] args) {
		String styles[] = { "001", "002", "003" };
		String colors[] = { "yellow", "pink", "green" };
		int sizes[] = { 7, 6, 4, 8 };
		char[] genders = { 'm', 'f' };
		combinations(styles, colors, sizes, genders);
	}

	public static void combinations(String[] styles, String[] colors,
			int[] sizes, char[] genders) {
		List<Product> products = new ArrayList<>();
		for (String style : styles) {
			for (String color : colors) {
				for (int size : sizes) {
					for (char gender : genders) {
						Product product = new Product(style, color, size,
								gender);
						products.add(product);
					}
				}
			}
		}
		System.out.println("Total Combination Of Products"+products.size());
		for (Product product : products) {
			System.out.println(product);
		}
	}
}

class Product {
	String style, color;
	int size;
	char gender;

	public Product(String style, String color, int size, char gender) {
		this.style = style;
		this.color = color;
		this.size = size;
		this.gender = gender;
	}

	@Override
	public String toString() {
		return "Product [style=" + style + ", color=" + color + ", size="
				+ size + ", gender=" + gender + "]";
	}

}
Output:
Total Combination Of Products72
Product [style=001, color=yellow, size=7, gender=m]
Product [style=001, color=yellow, size=7, gender=f]
Product [style=001, color=yellow, size=6, gender=m]
Product [style=001, color=yellow, size=6, gender=f]
Product [style=001, color=yellow, size=4, gender=m]
Product [style=001, color=yellow, size=4, gender=f]
Product [style=001, color=yellow, size=8, gender=m]
Product [style=001, color=yellow, size=8, gender=f]
Product [style=001, color=pink, size=7, gender=m]
Product [style=001, color=pink, size=7, gender=f]
Product [style=001, color=pink, size=6, gender=m]
Product [style=001, color=pink, size=6, gender=f]
Product [style=001, color=pink, size=4, gender=m]
Product [style=001, color=pink, size=4, gender=f]
Product [style=001, color=pink, size=8, gender=m]
Product [style=001, color=pink, size=8, gender=f]
Product [style=001, color=green, size=7, gender=m]
Product [style=001, color=green, size=7, gender=f]
Product [style=001, color=green, size=6, gender=m]
Product [style=001, color=green, size=6, gender=f]
Product [style=001, color=green, size=4, gender=m]
Product [style=001, color=green, size=4, gender=f]
Product [style=001, color=green, size=8, gender=m]
Product [style=001, color=green, size=8, gender=f]
Product [style=002, color=yellow, size=7, gender=m]
Product [style=002, color=yellow, size=7, gender=f]
Product [style=002, color=yellow, size=6, gender=m]
Product [style=002, color=yellow, size=6, gender=f]
Product [style=002, color=yellow, size=4, gender=m]
Product [style=002, color=yellow, size=4, gender=f]
Product [style=002, color=yellow, size=8, gender=m]
Product [style=002, color=yellow, size=8, gender=f]
Product [style=002, color=pink, size=7, gender=m]
Product [style=002, color=pink, size=7, gender=f]
Product [style=002, color=pink, size=6, gender=m]
Product [style=002, color=pink, size=6, gender=f]
Product [style=002, color=pink, size=4, gender=m]
Product [style=002, color=pink, size=4, gender=f]
Product [style=002, color=pink, size=8, gender=m]
Product [style=002, color=pink, size=8, gender=f]
Product [style=002, color=green, size=7, gender=m]
Product [style=002, color=green, size=7, gender=f]
Product [style=002, color=green, size=6, gender=m]
Product [style=002, color=green, size=6, gender=f]
Product [style=002, color=green, size=4, gender=m]
Product [style=002, color=green, size=4, gender=f]
Product [style=002, color=green, size=8, gender=m]
Product [style=002, color=green, size=8, gender=f]
Product [style=003, color=yellow, size=7, gender=m]
Product [style=003, color=yellow, size=7, gender=f]
Product [style=003, color=yellow, size=6, gender=m]
Product [style=003, color=yellow, size=6, gender=f]
Product [style=003, color=yellow, size=4, gender=m]
Product [style=003, color=yellow, size=4, gender=f]
Product [style=003, color=yellow, size=8, gender=m]
Product [style=003, color=yellow, size=8, gender=f]
Product [style=003, color=pink, size=7, gender=m]
Product [style=003, color=pink, size=7, gender=f]
Product [style=003, color=pink, size=6, gender=m]
Product [style=003, color=pink, size=6, gender=f]
Product [style=003, color=pink, size=4, gender=m]
Product [style=003, color=pink, size=4, gender=f]
Product [style=003, color=pink, size=8, gender=m]
Product [style=003, color=pink, size=8, gender=f]
Product [style=003, color=green, size=7, gender=m]
Product [style=003, color=green, size=7, gender=f]
Product [style=003, color=green, size=6, gender=m]
Product [style=003, color=green, size=6, gender=f]
Product [style=003, color=green, size=4, gender=m]
Product [style=003, color=green, size=4, gender=f]
Product [style=003, color=green, size=8, gender=m]
Product [style=003, color=green, size=8, gender=f]

- Srinivas June 27, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More