Results 1 to 4 of 4
Thread: Why do I get this output?
- 09-22-2010, 09:18 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 21
- Rep Power
- 0
Why do I get this output?
output isJava Code:public class testing { public static void main(String[] args) { final int a = 2, b = 3; System.out.println(a + "2"); [COLOR="Red"]System.out.println(a + '2');[/COLOR] System.out.println("2" + a + b); System.out.println("2" + (a + b)); System.exit(0); } }
22
52
223
25
How does the red highlighted code work? Thanks!- Winners compare their achievements with their goals, while losers compare their achievements with those of other people. -
- 09-22-2010, 10:10 PM #2
chars can be converted by the compiler to their ASCII value. If you lookup the ASCII codes table you will see that the int value of '2' is 50.System.out.println(a + '2');
- 09-23-2010, 08:03 AM #3
There's no conversion involved. The Java primitive char is an integral type.
Types, Values, and Variables
db
- 09-23-2010, 08:07 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
output
By yrollgayanth in forum New To JavaReplies: 5Last Post: 12-30-2009, 05:05 PM -
Where is output.txt?
By Jessaurum in forum New To JavaReplies: 3Last Post: 11-18-2009, 06:14 AM -
Java, output string, getting correct output? HELP!
By computerboyo in forum New To JavaReplies: 2Last Post: 02-25-2009, 11:44 PM -
how to c the output
By pro85 in forum Java AppletsReplies: 1Last Post: 02-11-2009, 09:09 AM -
Why the output is always zero
By mehrotra.chitij in forum New To JavaReplies: 12Last Post: 04-25-2008, 04:05 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks