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:
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?
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
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?
Page 1 of 1
Trackbacks for this entry [ Trackback URL ]
Tags
My Blog Links
Recent Entries
Recent Comments
Search My Blog
0 user(s) viewing
0 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)
Categories
|
|



2 Comments









|