Question: write code Write a boolean method named containsonlyDigits. The method should receive a String and determine whether the String contains only digits. Examples: - containsonlyoigits(571)

write code
write code Write a boolean method named containsonlyDigits. The method should receive

Write a boolean method named containsonlyDigits. The method should receive a String and determine whether the String contains only digits. Examples: - containsonlyoigits("571") should be true - containsonlypigits ("5s1") should be false - containsonlydigits("5") should be true - containsonlyDigits (") should be true Tip: you may want to use the charAt method of the String class and the isDigit method of the Character class. Note that the re's a difference in the way you invoke these two methods. To invoke the charat method, you need to first have a String object; for example, if s is a String, you can say s . charat(2). On the other hand, to invoke the isDigit method, you just use the name of the class; for example, Character.iabigit('7.). (As we'll learn, methods like charat are called instance mothods, while methods like inDigit are called static methods.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!