Subscribe to extremeblueness' Blog        RSS Feed
-----

char Variables

Icon 2 Comments
Yesterday in my Basic Programming class, I had need of the symbol pi to do some math in order to write code for circle statistics. Since I couldn't find the Ascii number for pi online, I wrote code to display all char values with their number equivalent:

public class AsciiValues
{
    public static void main(String args[])
    {
        char ascii = 0;
        int value = 0;
        while (value <= 65535)
        {
            System.out.println(value + ": " + ascii);
            ascii++;
            value++;
        }
    }
}



Using this code, I sifted through the values until I found pi, at 1289.

My programming teacher had two reactions:

1. Was somewhat impressed and assigned exactly what I did to his AP Computer Science class (only a couple of them were able to figure it out for some odd reason).

2. Faced a logical dilemma. The assignment intended us to make an estimate of pi using Math.pi (but didn't specify not to use the symbol pi). However, since what I did was more accurate than any estimate of pi, he couldn't logically get on to me for doing this.


By the way, does anyone have any idea why the AP Computer Science class had trouble with it?

2 Comments On This Entry

Page 1 of 1

jjl Icon

17 November 2012 - 01:05 PM

Quote

By the way, does anyone have any idea why the AP Computer Science class had trouble with it?

Pi isn't defined in the standard ascii set. Java defines char as 16-bit unicode characters, rather than C/C++ where chars are 8-bit ascii characters.

How did having the unicode symbol for pi improve your estimate of pi?
0

extremeblueness Icon

18 November 2012 - 09:25 AM
It didn't. I used the symbol pi instead of the estimate.
0
Page 1 of 1

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

December 2014

S M T W T F S
 123456
78910111213
14151617181920
212223 24 252627
28293031   

Tags

    Recent Entries

    Recent Comments

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)

    Categories