Results 1 to 3 of 3
- 01-10-2013, 06:56 PM #1
Member
- Join Date
- Feb 2012
- Location
- UK
- Posts
- 16
- Rep Power
- 0
(char)
The output I get is xJava Code:public class prg { public static void main(String[]args) { int i; i=10; char a = 'n'; System.out.println((char)('n'+i)); //<--------------- } }
Similarly if it is (char)('n'+2),output is p
I really don't get it.What is happening here? What does (char) actually do?
- 01-10-2013, 06:59 PM #2
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: (char)
char is an integer describing a characters code. So you can modify it by adding integers to get other characters.
EDIT: (char) casts an integer to a character interpreting it as character code, google "java type casting" maybe to get more info about casts.Last edited by Sierra; 01-10-2013 at 07:18 PM.
I like likes!.gif)
- 01-10-2013, 07:06 PM #3
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: (char)
Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
"char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive)."
Unicode Zeichentabelle
n = 6e hex = 110 dec
110 + 10 = 120 dec = 78 hex = x
Similar Threads
-
concatenate two char into one char
By nadissen in forum EclipseReplies: 3Last Post: 04-06-2011, 02:40 PM -
searching char array with another char array for full word matches
By karunabdc in forum New To JavaReplies: 2Last Post: 03-08-2011, 06:20 AM -
check a string char by char
By Sotsiak in forum New To JavaReplies: 2Last Post: 10-23-2010, 09:24 PM -
replaceALL(char oldChar, char newChar) method
By arson09 in forum New To JavaReplies: 0Last Post: 04-28-2010, 05:48 AM -
drawing char by char with Graphics
By diggitydoggz in forum New To JavaReplies: 5Last Post: 12-27-2008, 12:49 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks