design a nested loop that displays 10 rows of # characters. There should be 15 #
ID: 3734080 • Letter: D
Question
design a nested loop that displays 10 rows of # characters. There should be 15 # characters in each row.
Need to show this in psuedocode. This is what I have so far....
Declare Integer hashNum
Declare Integer numRows
Declare String hash = "#"
Constant Integer MAX_HASH = 15
Constant Integer MAX_ROWS = 10
For numRows = 1 To MAX_ROWS
Dispaly hash
For hashNum = 1 to MAX_HASH
hash = hash + "#"
End For
End For
Explanation / Answer
DisplayHash.java
public class DisplayHash {
public static void main(String[] args) {
int numRows, hashNum;
String hash = "#";
final int MAX_HASH = 15;
final int MAX_ROWS = 10;
for( numRows =0;numRows <MAX_ROWS ;numRows ++) {
hash = "#";
for( hashNum=0;hashNum<MAX_HASH-1;hashNum++) {
hash=hash+"#";
}
System.out.println(hash);
}
}
}
Output:
###############
###############
###############
###############
###############
###############
###############
###############
###############
###############
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.