some java confusion, please help

xyyz

Diamond Member
Sep 3, 2000
4,331
0
0

I'm trying to learn Java on my own...

I'm using Walter Savitch's text.

He says the following:

"You can assign a value of type char to a variable of type int, or to any of the numeric types that follow int in our list of type. "

I don't get this. Is he saying you can assign a letter to type int? If so, that makes no sense.
 

Mday

Lifer
Oct 14, 1999
18,647
1
81
a letter is a character.

a character is represented by an ascii number. that is that.

so int i = 'a' is a legal argument
 

Chad

Platinum Member
Oct 11, 1999
2,224
0
76
Yes, so the int takes up the numeric representation of the letter. But I believe it's the Unicode representation, not the ASCII.
 

xyyz

Diamond Member
Sep 3, 2000
4,331
0
0

thanks for the explanation guys...

Savitch did cover it a bit later... I wish he'd covered it sooner.

but he used the example of printing the conversion of 7 from a char to an int, the result would give you 55 and not 7, because of the unicode.

honestly, your explanations were better.

thanks again.
 

Chad

Platinum Member
Oct 11, 1999
2,224
0
76
Yeah, he probably should have been more clear, but I really like Savitch. I think his books are some of the best.

Are you reading the "Java: An Introduction to Computer Science & Programming" book of his?
 

ugh

Platinum Member
Feb 6, 2000
2,563
0
0
While we're in the subject, anyone knows the difference between char and byte?