Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

Can anyone help me how I can able to figure it out that a number is double or not? I am using this syntax:

if ( typeof ( items.elementAt(1) )== Double ) {

       sum.add( i, items.elementAt(1));

}

How can I make it work properly?

1 Answer

0 votes
by (26.7k points)

You can try with this code:

if (items.elementAt(1) instanceof Double) {

   sum.add( i, items.elementAt(1));

}

I hope this will help.

Want to become a Java expert? join Java Training now!!

Related questions

0 votes
1 answer
asked Mar 7, 2021 in Java by Jake (7k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...