Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

View RSS Feed

JD1's Personal Development Blog

Math Class Methods

Rate this Entry
There are many built in methods we can use to conduct mathematical operations to numbers. Here are some of them.

class Class1{
	public static void main(String args[]){
		//How far number is from zero.
		System.out.println(Math.abs(-26.7));
		//Rounds number up.
		System.out.println(Math.ceil(7.4));
		//Rounds number down.
		System.out.println(Math.floor(7.8));
		//Greater of the two numbers.
		System.out.println(Math.max(8.6, 5.2));
		//Smaller of the two numbers.
		System.out.println(Math.min(8.6, 5.2));
		//First number to the power of the second number.
		System.out.println(Math.pow(5, 3));
		//Square root of the number.
		System.out.println(Math.sqrt(9));
	}
}

All pretty self explanatory.
Categories
Uncategorized

Comments