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);
			}
			
			
	}

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.

Yes, thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.