Download presentation
Presentation is loading. Please wait.
Published byGary Richardson Modified over 8 years ago
1
Special Methods in Java
2
Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double a, double b) // will raise a to b Math.sqrt(double a)// will return the square root of a Math.random()// generates random numbers
3
Exercise 1 Write a program that will take ask for input of integers a, and then raise a to order of 8 times and return the square root of the final result. Display the final value
4
Exercise 2
5
Exercise 3 For every number from 1-50, list that number raised to the 5. Take that number now and list its third root.
6
String Methods String a = “Hello”; String b = “World”; String c = a + b; int a = c.length(); String j = c.substring(0,5); int a = c.indexof(“W”);
7
Exercise 1 Create a string called “This is an exercise of great importance.” Let me know when you first run into the letter ‘x’. Once you have the index. Display everything from that index to the end of the string.
8
Exercise 2 Create two strings. Ask the user to input values for both strings. Add these strings together and determine how big these strings are. Now start a for loop and start displaying this string but to a line feed after every five characters. Added bonus, do a line feed after every space rather than every 5 characters.
9
Exercise 3 Ask the user to enter a string. Once you have them, determine if the world “Hello” is in there somewhere.
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.