Computer Science > QUESTIONS & ANSWERS > Independence High School, TXCS 302 HappyNumbers-VEFIFIED BY EXPERTS-ALL ANSWERS CORRECT (All)
Happy Numbers Recursion can be quite mind bending at first! The only way to get better at it is with practice (to understand recursion, you must first understand recursion). In this lab, the recursi... on problems get a bit trickier. A recursive method must have a base case! A base case is a problem so simple, you can solve it immediately. Otherwise (if the base case hasn't been reached), your method should attempt to break to the problem up into smaller pieces, such that you're now trying to solve a smaller subset of a larger, more complex problem. 1. Write a recursive method that determines if the String parameter is a palindrome. Always start with your base case, a problem so simple it can be solved immediately! If you haven't reached your base case, attempt to break the problem up into smaller pieces until you do. 2. Write a recursive method that will return true if a number is prime. a. Your method will need two parameters. Think about how the prime checker algorithm works with a for loop, then convert the algorithm to use recursion: for (int i = 2; i < num; i++) if (num % i == 0) //not prime if i is a factor of num 3. Complete the method public void timesTwo(int n) that prints the value of n factored into some number of 2s multiplied by a single odd number. You can assume n will be even. timesTwo(80) >>> 2 * 2 * 2 * 2 * 5 timesTwo(68) >>> 2 * 2 * 17 4. Early members of the Pythagorean Society defined "figurate numbers" to be the number of dots in certain geometrical configurations. The first four "triangular numbers" are 1, 3, 6, and 10: Page 1 of 5 [Show More]
Last updated: 1 year ago
Preview 1 out of 5 pages
Instant download
Buy this document to get the full access instantly
Instant Download Access after purchase
Add to cartInstant download
Connected school, study & course
About the document
Uploaded On
May 11, 2021
Number of pages
5
Written in
This document has been written for:
Uploaded
May 11, 2021
Downloads
0
Views
30
In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Browsegrades · High quality services·