1 / 8

Chapter 5 Practice

Chapter 5 Practice. Practice with void method. Write a void dozens(int n) method that converts n into dozens.

simon-tyson
Download Presentation

Chapter 5 Practice

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 5 Practice

  2. Practice with void method Write a void dozens(int n) method that converts n into dozens. A dozen of apples is 12 apples. Given a natural number n (number of apples), it can convert n into number of dozens and the remaining number of apples. For example, if you have 35 apples, it will display “ You have 2 dozens and 11 apples.” dozens(35)  “ You have 2 dozens and 11 apples.”

  3. Practice with void method Write a void hms(int n) method that converts n into hours, minutes and second. hms(3672)  “ 1 hour 1 minute and 12 seconds.”

  4. Practice with boolean method A number n ≥ 10 is called “good” if the last 2 digits has a sum of 9. For example, 3472, 124936 are good numbers. Write a boolean isGood(int n) method that returns true if n is a good number, or false otherwise.

  5. Practice with boolean method Write a boolean isPrime(int n) method that returns true if n is a prime number, or false otherwise. Note that a prime number is a number p > 1 which is only divisibe by 1 and itself.

  6. Practice with char method Write a char mode(String s) method that returns a character that appear most frequently in the string s. If there are more than 1 such chracters, return the first one. For example, mode(“hello”)  ‘l’ mode(“saigontech”)  ‘s’ mode(“hoang thuy linh”)  ‘h’

  7. Practice with int method Write a int sum(int n) method that returns the sum of all numbers from 1 to n. For example, sum(5)  15 sum(10)  55 sum(8)  36

  8. Practice with double method Write a double circleArea(double r) method that returns the area of a circle having radius r, rounded with 2 decimal places. For example, circleArea(1)  3.14 circleArea (10)  314.16

More Related