Stars - if(start == peak printNStars(peak else...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
public class Stars{ public static String nChars(int n, char c){ String chars = ""; for (int j=0; j<n; j++){ chars = chars + c; } return chars; } public static void printNStars(int n){ System.out.println(nChars(n,'*')); } public static String nSpaces(int n){ return nChars(n, ' '); } public static void printNSpaces(int n){ System.out.println(nChars(n, ' ')); } public static void bowtie(int n){ if (n==1){ printNStars(1); } else { printNStars(n); bowtie(n-1); printNStars(n); } } public static void hill(int start, int peak){
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if(start == peak){ printNStars(peak); } else { printNStars(start); hill(start+1, peak); printNStars(start); } } public static void bigX(int size, int indent){ ; if (size==1){ System.out.println(nSpaces(indent) + "x"); } else { System.out.println(nSpaces(indent) + "x" + nSpaces(2*size-3) + "x"); bigX(size-1, indent+1); System.out.println(nSpaces(indent) + "x" + nSpaces(2*size-3) + "x"); } } public static void main(String args){ bigX(4,0); bowtie(4); hill(2,4); } }...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

Stars - if(start == peak printNStars(peak else...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online