Results 1 to 2 of 2
Thread: simple ASCII Table help
- 01-20-2010, 08:28 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 4
- Rep Power
- 0
simple ASCII Table help
Hi i need to create a table that looks like this

I also need to set from integer value 32 to 126.
Does anyone know how to get the character column on that picture
this is what code I have so far. Any help would be greatly appreciated
Thank you very much
Java Code:/** * Write a description of class hw2 here. * * @author (your name) * @version (a version number or a date) */ public class hw2 { // instance variables - replace the example below with your own private int x; /** * Constructor for objects of class hw2 */ public hw2() { // initialise instance variables x = 0; } /** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ public void one() { // put your code here System.out.println("Value Character"); for(int i = 32; i < 127; i++){ System.out.println( i ); } } }
- 01-20-2010, 09:28 PM #2
uh, cast the integer i here as a char
such as
or to put it self contained examply,Java Code:System.out.println( (char) i);
or more eloquently,Java Code:/** * @author thein * */ public class AciiTable { public static void main(String[] args) { System.out.println("Value Hex Character"); for(int i = 32; i < 127; i++){ // because the i will go from 2 decimals to 3 decimal places // we convert it to a string here before just printing it, // so that we can enforce its length always 3 for pretty printing. String value = String.valueOf(i); if (value.length() < 3) { value = " " + value; } String hex = Integer.toHexString(i); System.out.println( value + " " + hex + " " + (char)i); } } }
Java Code:/** * @author thein * */ public class TwoColumnAciiTable { private static String render(int i) { // because the i will go from 2 decimals to 3 decimal places // we convert it to a string here before just printing it, // so that we can enforce its length always 3 for pretty printing. String value = String.valueOf(i); if (value.length() < 3) { value = " " + value; } String hex = Integer.toHexString(i); return new String(value + " " + hex + " " + (char)i); } public static void main(String[] args) { System.out.println("Value Hex Character Value Hex Character"); int start = 32; int end = 127; int mid = (end-start)/2 + 1; for(int i = 0; i < mid; i++) { String line = render(i+start) + " "; if (i + start + mid < end) { line += render(i + start + mid); } System.out.println(line); } } }Last edited by travishein; 01-20-2010 at 09:38 PM.
Similar Threads
-
How to repaint.refresh the table (table model) with combo box selection envent
By man4ish in forum AWT / SwingReplies: 1Last Post: 01-08-2010, 06:19 AM -
Super simple table applet
By danwoods in forum New To JavaReplies: 4Last Post: 10-21-2009, 12:58 PM -
Getting ascii from a String
By ali_sakar in forum New To JavaReplies: 1Last Post: 03-07-2009, 10:11 AM -
Simple Table Example
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:58 PM -
Displaying ASCII Codes in a table
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks