i am new in java ... i would like to know how 2 maintain an integer without having it to show the decimal after i manipulate it. Example:

int y = 5;
System.out.print(Math.pow(y,2));

it display 25.0 instead of 25 which i wan it to be. Help would be very appreciate :)

Recommended Answers

All 7 Replies

Math.pow takes two floating-point numbers and returns a floating-point number

maybe you want to convert it to an int first?

i see... how can i convert floating-point into integer in this case?

Try something like this:

(int)Math.pow(y,2);

or

System.out.println((int)Math.pow(y,2));

if you want to print

i see, it works...thx... oh ya one more things i would like to know. How u make ur java code appeared with a different backgroud colour(in this forum)? i am also new in daniweb... i read the notice about bb code, but i am still dont understand ...

Right above the text area where you write your reply there are tools for writing in bold or underlying. The 3rd from the right which is a "#" symbol is the code tag. Click it and write your code inside the tags.

i m new to daniweb....i know this question is totally irrelevant to the topic but i need to know how to start a new thread ...?!!

Click the "start new thread" link/button at the page where you view all the posts

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.