Epic Systems Interview Question
Software Engineer / Developersvoid printStar(int numLine)
{
String line = "";
for (int i=0; i<numLine; i++)
{
line.concat("*");
System.out.println(line);
System.out.println("\n");
}
}
static void printTriangle(int n)
{
for (int i = 0; i < n; i++)
{
string _s = null;
for (int j = 0; j <= i; j++)
{
_s += "*";
}
Console.WriteLine(_s);
}
}
static void printTriangle1(int n)
{
string _s = null;
for (int i = 0; i < n; i++)
{
_s += "*";
Console.WriteLine(_s);
}
}
//Two functions for printing triangle
//previous one is not optimized this is perfect 2 solutions
static void printTriangle(int n)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
static void printTriangle1(int n)
{
string _s = null;
for (int i = 0; i < n; i++)
{
_s += "*";
Console.WriteLine(_s);
}
}
// To print a triangle of stars of a given height
//======================================================
#include <iostream>
using namespace std;
void printTriangle(int height) {
for (int i = 0; i < height; ++i ) {
for ( int j = 0; j <= i; ++j ) {
cout << '*';
}
cout << "\n";
}
}
int main() {
int height;
cout<<"Enter the height of the triangle: ";
cin>>height;
printTriangle(height);
return 0;
}
//===================================================
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
public static int len = 0;
static void Main(string[] args)
{
printstart(3);
Console.ReadLine();
}
static void printstart(int numline)
{
string line = "";
for (int i = 1; i <= numline; i++)
{
line = line.PadLeft(i,'*');
Console.WriteLine(line);
}
}
}
}
<pre lang="" line="1" title="CodeMonkey48889" class="run-this">public void printTriangle (int height, int width) {
String line = "";
for(int i = width; i > 0; i--) {
int j = i;
if (height > 0) {
while (j > 0) {
line = line.concat("*");
j --;
}// end while
System.out.println(line);
line = "";
height--;
} // end if
else
break;
} // end for
}
</pre><pre title="CodeMonkey48889" input="yes">
</pre>
<pre lang="" line="1" title="CodeMonkey66197" class="run-this">public void printTriangle (int height, int width) {
String line = "";
for(int i = width; i > 0; i--) {
int j = i;
if (height > 0) {
while (j > 0) {
line = line.concat("*");
j --;
}// end while
System.out.println(line);
line = "";
height--;
} // end if
else
break;
} // end for
}
</pre><pre title="CodeMonkey66197" input="yes">
</pre>
static void printStar(int num)
{
StringBuilder line = new StringBuilder();
for (int i=0; i<num; i++)
{
line.append("*");
System.out.print(line);
System.out.print("\n");
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package starpyramid;
/**
*
* @author swetalina
*/
public class StarPyramid {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
StarPyramid(8);
}
public static void StarPyramid(int i)
{
for(int k=1;k<=i;k++){
for(int j=1;j<=k;j++)
{
System.out.print("*");
}
System.out.println("\n");
}
}
}
public class stars {
public static void main(String[] args) {
String str = "*";
for(int i = 1;i <= 5;i++){
for(int j = 1; j<=i;j++){
System.out.print(str);
}
System.out.println();
}
}
}
function to draw a triangle given the height and width (not just height like most of the above solutions).
- agnithin August 21, 2012private static void drawTri(int height, int width) {
for(int i=1; i<=height; i++){
for(int j=0; j<(i*(width/height)); j++){
System.out.print("*");
}
System.out.print("\n");
}
}