• 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

ID:7 SCJP Question of the day !!!

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: https://coderanch.com/t/498524/java-programmer-SCJP/certification/ID-SCJP-day-Wednesday-June

[HENRY: Added link to rules]
 
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic