• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ID:7 SCJP Question of the day !!!

 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following program and tell the Output ???



Thanks !!!
Looking for other pals to continue this theme or series of questions !!!



Link to rules: http://www.coderanch.com/t/498524/java-programmer-SCJP/certification/ID-SCJP-day-Wednesday-June

[HENRY: Added link to rules]
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found Float 14.4 //Found Double 14.4
Found Short 1
Found Short 2
Found Short 3
Found Short 4
Found Short 127
Found Short 128
Found Short 32767
Found Integer 32768
Waste 12L // Found Long 12L
Waste 13.2f // Found Float 13.2f
Found Float 14.3
Found Short 143


i tried it myself and then run it using jcreator
there are 3 places where i went wrong(marked as comments)
can anbody explain why
the first line of output is
Found Float 14.4
as
Float as=14.4; gives compiler error
and
similarly,
long can be assigned 12L and float can be asssigned 13.2f so, why waste is in the output
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found float 14.4
Found Short 1
Found Short 2
Found Short 3
Found Short 4
Found Short 127
Found Short 128
Found Short 32767
Found Integer 32768
Found Long 12
Found Float 13.2
Found Float 14.3
Found Short 143
123
[some negative value]


... I think ;)
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After some testing I realized results are probably local dependant.



output is:


Where I come form ',' is considered as a decimal separator. A minor change in code gets what we're going for


output is:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic