This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a quick question

 
Howard Kung
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
My computer is down, so I can't compile any java code.
Here is my question:
what will be the output of this--
char s = 3;
System.out.println(s);
Thanks
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It prints out: "LOVE"
 
Howard Kung
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
funny guy
 
Anu Kha
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya it displays the ascii for 3
this info is just for others who might be confused why this happens.
Well if u say
char s =3 and then print s u will print the ascii char which is represented by 3
if u say char s = '3' then u get 3 as output.
 
Sayed Ibrahim Hashimi
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which happens to be the sign of a heart...so they guy really wasn't being that funny.
 
Sayed Ibrahim Hashimi
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As an added note.
I wrote the following class

I had to skip over 9 and 100. I'm running winxp and at 9 and 100 the computer would beep then stop executing the loop. Does anyone know why?
[ August 08, 2002: Message edited by: Ibrahim Hashimi ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's take a look at http://www.asciitable.com to see what those characters are and why issues might arise when displaying them...
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm running Windows XP and I could not replicate your problem. (char)9 is the horizontal tab and (char)100 is 'd'. This program displays the corresponding characters as expected:
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
char s ;

I think it's a bad idea to name a char 's'

I had to skip over 9 and 100. I'm running winxp and at 9 and 100 the computer would beep then stop executing the loop. Does anyone know why?
Like Dirk, I had no problems with 9 and/or 100
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic