This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP and have Lucian Maly on-line!
See this thread for details.
Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Dan Chisholm's math topic exam question

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Dan Chisholm's java.lang.Math topic exam,
question #8 looks like this
class C {
public static void main (String[] args) {
int i1 = Math.round(0.5f);
int i2 = Math.round(1.5f);
System.out.print(i1 + "," + i2);
}
}

What is the result of attempting to compile and run the program?
a. Prints: 0.0,1.0
b. Prints: 0.0,2.0
c. Prints: 1.0,1.0
d. Prints: 1.0,2.0
e. Compiler Error
f. Runtime Error
g. None of the Above
I thought it would be g, since the return type is int and the answer would be 1,2. But the answer says d it prints 1.0, 2.0. I compiled and it executed as 1,2. Did I miss something? or is the answer wrong?
Love the topic exams, by the way. Thanks so much Dan.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barb,
Yes, you are correct.
The corrected version is now up on the web site.
Thank you,
Dan
[ August 06, 2002: Message edited by: Dan Chisholm ]
 
Arthur, where are your pants? Check under this tiny ad.
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic