RowsOfCharsConsole

RowsOfCharsConsole - // containing 25 copies of that...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Simulation of console-I/O program RowsOfChars, using ConsoleApplet as a basis. See the file ConsoleApplet.java for more information. David Eck eck@hws.edu */ * public class RowsOfCharsConsole extends ConsoleApplet { p protected String getTitle() { return "Sample program \"RowsOfChars\""; } protected void program() { String inputLine; // Line of text input by user. console.put("Enter a line of text: "); inputLine = console.getln(); console.putln(); printRowsFromString( inputLine ); } void printRowsFromString( String str ) { // For each character in str, write a line of output
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // containing 25 copies of that character. int i; // Loop-control variable for counting off the chars. for ( i = 0; i < str.length(); i++ ) { printRow( str.charAt(i), 25 ); } } void printRow( char ch, int N ) { // Write one line of output containing N copies of the // character ch. If N <= 0, an empty line is output. int i; // Loop-control variable for counting off the copies. for ( i = 1; i <= N; i++ ) { console.put( ch ); } console.putln(); } }...
View Full Document

Ask a homework question - tutors are online