Interview Question
Java DevelopersCountry: India
Interview Type: In-Person
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("");
}
}
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));
}
}
public class PrintStars {
String text = "*";
for(i=0;i<5;i++){
System.out.print(text);
text=text+"*";
}
}
}
...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());
}
}
}
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");
}
}
}
Another dumb question I came across online - I wish they get their questions more serious & mature before throwing at candidates.
- Itanium August 26, 2014