0

I am trying to make a table of all the ASCII characters but am having some trouble. I have all the characters printed in a list order, but need to make it into about 10 columns across. Any help is really appreciated. Here is my code so far...

import corejava.*;
 
public class Ascii {
 
	public static void main(String[] args) {
		
			System.out.println("Standard ASCII Codes");
			
			System.out.println("008 - BS");
			System.out.println("009 - TAB");
			System.out.println("010 - LF");
			System.out.println("013 - CR");
			
			for (int i = 33; i < 127; i ++){
				Format.print(System.out, "%03d", i);
				System.out.println(" - " + (char)i);
			}
			System.out.print("127 - DEL");
			
			
			System.out.println("");
			
			String prompt = Console.readString("Press Enter to Continue");
			
			System.out.println("Extended ASCII Codes");
			
			for (int i = 128; i < 256; i++){
				System.out.println(i + " - " + (char)i);
			}
			
			
	}
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by jls7168
1

You will need to use a nested for loop if you want to print fixed number of characters horizontally also.

Following is how you loop would look like (note it is just for an illustration, you may have to modify it further to get what you exactly want) :-

final int noOfCharsPerLine = 10;
    for (int i = 128; i < 256; i++){
        for(int j=0; j< noOfCharsPerLine;i++,j++) {
            // Note the use of only "System.out.print"
	    System.out.print(i + " - " + (char)i + " ");
        }
        // To print on the next line after the 10 characters
        // have been printed.
        System.out.println();
    }

You will similarly have to modify your first loop.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.