Interview Question for Java Developers


Country: India
Interview Type: In-Person




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

Another dumb question I came across online - I wish they get their questions more serious & mature before throwing at candidates.

- Itanium August 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class PrintStars {
   public static void main(String[] args) {
      int i,j,n;
      n = Integer.parseInt(args[0]);//no of rows to print
      for(i=0;i<n;i++){
         for(j=0;j<=i;j++){
            System.out.print("*");
         }
      System.out.println("");
      }
   }
}

- vijay.edella August 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class printStars {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		for(int i=1; i<5; i++) {
			for(int j=1; j<=i; j++) {
				System.out.print("*");
			}
			System.out.println();
		}
	}

}

- austin August 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void printPyramid(int height){
		for (int row =0 ;row <height ; row++ )
		{
			for (int i= 0 ;i< row ;i++ )
			{
				System.out.print("*");
			}
			System.out.println("");
		}
	}

- SachinK August 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i<=row

- fReaK August 26, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class PrintStars {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int n = 1;
		String str = ""; 
		
			for(int i = 1;i <= 4; i++)
			{	
				while(n <= i)
				{
					str += "*";
					n++;
					
				}
				
				System.out.println(str);
				str = "";
				n = 1;	
			}
					
		}
	}

- yunjin.choi.sa August 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Seriously , this question was asked in your interview ?

- praveenkcs28 August 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package gao.zone.study;

import java.util.Arrays;

public class PrintAsteriskTraingle {

	public static void main(String[] args) {
		print(1, 4, 1);
	}

	private static void print(int min, int max, int step) {
		for (int i = min; i <= max; i += step) {
			printLine(i);
		}
	}

	private static void printLine(int length) {
		char[] chars = new char[length];
		Arrays.fill(chars, '*');
		System.out.println(String.valueOf(chars));
	}
}

- ttoommbb@126.com September 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class PrintStars {
String text = "*";
for(i=0;i<5;i++){
System.out.print(text);
text=text+"*";
}
}
}

- squid September 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

wrong output

- beginner September 09, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Use "println"

- Naga Praveen September 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

...was this a serious question? I may have laughed if they asked it.

import java.lang.StringBuilder;

public class Test {
	public static void main(String[] args) {
		StringBuilder sb = new StringBuilder();
		for (int itr = 0; itr < 4; itr++) {
			sb.append("*");
			System.out.println(sb.toString());
		}
	}
}

- Anonymous September 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;

public class StarTree {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);
System.out.println("Enter number .... ");
int noofrows = input.nextInt();

for (int i = 0; i < noofrows; i++) {
for (int j = 0; j <=i; j++) {
System.out.print("* ");
}
System.out.println("\n");
}
}
}

- Diptendu December 31, 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