Exercise 05.15 (Introduction to Java, Programming and Data Structures) (Display
ID: 3707712 • Letter: E
Question
Exercise 05.15 (Introduction to Java, Programming and Data Structures)
(Display the ASCII character table) Write a program that prints the characters in the ASCII character table from ! to ~. Display 10 characters per line. The ASCII table is given in Appendix B. Characters are separated by exactly one space.
This is my current code.
It currently runs and displays the table correctly but my teacher said "Line 23 to 32, use % 10 to check if there are 10 numbers printed on a row????????????????????? to replace the || expressions.??????????????????????"
Explanation / Answer
Given below is the modified code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
public class Exercise05_15{
public static void main (String[] args){
//storing the starting ASCII character within "letter"
char letter = '!';
//this will be my counter for a set number of loops
int count = 0;
//Loop to print out the correct number of ASCII characters
while (letter <= '~') {
System.out.print(letter++);
System.out.print(" ");
count++;
if(count % 10 == 0) //if 10 letters are printed, print newline
System.out.println();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.