Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
need clairifications about char type
nada saif
Greenhorn
Posts: 8
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi all ,
I found a strange code i couldn't understand , will be great if any can explain how
Java
compiler translate it
class a{ public static void main(String arg[]) { char a=5; short x=3; x*=a; // x=x*a; error System.out.println(x); } }
Output is 15
my Questions are
1- can we use char as number??
2- what is the difference the example above between line 5 ,6
Thanks in advance
Nada
Venu Chakravorty
Ranch Hand
Posts: 46
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
1. 'char' is actually a 16-bit unsigned 'int'
2. in line 5 there is an implicit cast, in line 6 you have to cast the resulting 'int' to a
'short'
nada saif
Greenhorn
Posts: 8
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thank you venu ,
But how char is an integer , i am lost ..
can you elaborate in this point .. or post some useful URLs..
Bests,
Nada
Campbell Ritchie
Marshal
Posts: 79177
377
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Java™ Language Specification
. That's the link. It will (I hope) tell you that the
char
type is an unsigned integer type.
Try this:
for (int c = 'a'; c <= 'z'; c++) { System.out.printf("The letter %c is the %dth in the alphabet.%n", c, c % 0x20); }
nada saif
Greenhorn
Posts: 8
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks guys, i really appreciate your sense of cooperation .
Good luck.
Nada
Campbell Ritchie
Marshal
Posts: 79177
377
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You're welcome
Venu Chakravorty
Ranch Hand
Posts: 46
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
you're welcome.
jami siva
Ranch Hand
Posts: 66
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The
word
of saying 'Thanks' after getting the reply is boosting for the people who post answers.
Hoo hoo hoo! Looks like we got a live one! Here, wave this tiny ad at it:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
implicit casting of final int to byte ???
Trouble with system.in manipulation
Assignment
Reading a char from int
printf string formatting
Thread Boost feature
More...