// Name: Anita Blake Partner: Ted Forrester // ID: 014916 ID: 642708 // Sec: Yan T 2:30 Sec: Artemov R 1:25 // Date: Feb 22, 2000 // Project 3: Stars and Loops Forever! import java.text.DecimalFormat; // for BONUS labels // print LAST longest run of consecutive-increasing integers in // a sequence of non-0 integers public class Project3_1 { public static void main(String[] args) { TokenReader in = new TokenReader(System.in); int next = in .readInt(); // next value to process int maxlo = 0; // start of last longest run so far int maxhi = -1; // end of last longest run so far int prevhi = next - 2; // previous value -- obviously, // end of longest run ending on prev int prevlo = next; // start of longest run ending on prev // read input until reach a 0, maintaining variables as defined above while (next != 0) { // update longest run ending on prevhi=next if (next != prevhi + 1) prevlo = next; prevhi = next; // update last longest run so far if (prevhi-prevlo >= maxhi-maxlo) { // see REMARK below maxlo = prevlo; maxhi = prevhi; } // read next next = in.readInt(); } // print last longest run (or error message if none) if (maxhi=$, not $>$ // print fill-in triangle of stars with vertices (0,0), (10,0), and input (x,y) // BONUS: print x-position and y-position labels public class Project3_2 { public static void main(String[] args) { TokenReader in = new TokenReader(System.in); int leftx = 0, lefty = 0; // coords of top-left vertex int rightx = 10, righty = 0; // coords of top-right vertex int x = in.readInt(), y = in.readInt(); // coords of bottom vertex // assume input has x>=0, y>1 /*** BONUS ********************************************************/ /**/ // compute yfmt and print corresponding spaces /**/ /**/ String yfmt = "0"; // format string for y labels /**/ /**/ String pad = " "; // same-length padding /**/ /**/ for (int tmp = y; tmp>=10; tmp /= 10) { /**/ /**/ yfmt += "0"; /**/ /**/ pad += " "; /**/ /**/ } /**/ /**/ // Format for y labels /**/ /**/ DecimalFormat yformat = new DecimalFormat(yfmt); /**/ /**/ // print x labels /**/ /**/ int place = 10; // which digit/"place" to print /**/ /**/ int xmax = (int) Math.max(x,rightx); /**/ /**/ // compute place /**/ /**/ while (place <= xmax) place *= 10; /**/ /**/ // loop over each place to print x labels /**/ /**/ while (place>1) { /**/ /**/ place /= 10; /**/ /**/ System.out.print(pad); /**/ /**/ // print place-digits for each x-position h /**/ /**/ for (int h = 0; h <= xmax; h++) /**/ /**/ System.out.print((h/place) % 10); /**/ /**/ System.out.println(); /**/ /**/ } /**/ /******************************************************************/ // loop over each row to print filled-in triangle for (int row = (int) lefty; row <= y; row++) { /*** BONUS: ***************************************/ /**/ // print y label for current row /**/ /**/ System.out.print(yformat.format(row)); /**/ /**************************************************/ int col; // index of next column to print int left = leftx; // col where triangle starts on current row int right = rightx; // col where triangle ends on current row // compute left, right for non-degenerate triangle (y>0) if (y>0) { left = (x-left) * row / y + left; right = (x-right) * row / y + right; } // print leading spaces for (col = 0; col < left; col++) System.out.print(" "); // print filled-in stars for current row for ( ; col <= (int) right; col++) System.out.print("*"); // advance to next line System.out.println(); } } }