aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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
Author

Confusing me the two question?please help ~~

Tu Ran
Ranch Hand

Joined: Feb 09, 2002
Posts: 30
First:
" 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?)
Second:
class Test{
public static void main(String[] args){
float x=-214783650.6f;
System.out.println(Math.round(x));
}
}//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
Sheriff

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."


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[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="http://www.rajindery.com" 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: http://aspose.com/file-tools
 
subject: Confusing me the two question?please help ~~
 
Similar Threads
finalize method
Marcus Green Question(can any body explain
byte to char casting
Ternary operator with if/elseif/else
ternary operator