File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Confusing me the two question?please help ~~ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Confusing me the two question?please help ~~" Watch "Confusing me the two question?please help ~~" New topic

Confusing me the two question?please help ~~

Tu Ran
Ranch Hand

Joined: Feb 09, 2002
Posts: 30
" In this statement that uses the ternary operator: int a=b?c what
tye fo variable should b be?
A: an integer
B:the same variable type as 'c'
c:the same variable type as 'd'
d: the boolean
(I think no one correct answer?but I am wrong? why can you tell me?)
class Test{
public static void main(String[] args){
float x=-214783650.6f;
}//Why x=-214783648??? but I think x should equal to -214783651

Enjoy java,enjoy life
Po-yu Chien
Ranch Hand

Joined: Nov 01, 2001
Posts: 45
For ternary operator, I guess the boolean value
should be the answer.
It`s like:
if(b) {
a = c;
so b must be a boolean value.
However I cannot respond to your second question.
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
Tu Ran,
The Math.round() method taking a float as argument returns an int whose minimal value is -2147483648.
Moreover, the javadoc for Math.round() says that "If the argument is negative infinity or any value less than or equal to the value of Integer.MIN_VALUE, the result is equal to the value of Integer.MIN_VALUE."

[Blog] [Blogroll] [My Reviews] My Linked In
Rajinder Yadav
Ranch Hand

Joined: Jan 18, 2002
Posts: 178
The ternary operator is equivalent to the if/else,assignment constructor

So b must be a boolean value.
For your second question, you are converting a float to a int value using Math.round(), what you're seeing is called a "overflow" error.
Floating point values are stored differently then integer values, as such large values cannot truly have a one to one mapping between the two types!
[ February 22, 2002: Message edited by: Rajinder Yadav ]

<a href="" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes
Tu Ran
Ranch Hand

Joined: Feb 09, 2002
Posts: 30
Thanks my friends
Valentin Crettaz
Rajinder Yadav
Po-yu Chien
I will study hard in java~~thanks again!!
I agree. Here's the link:
subject: Confusing me the two question?please help ~~
It's not a secret anymore!