Write a recursive method called method3 that accepts an integer parameter and returns the integer reformed by repeating digits 1 and 2. For example, method3 (123456) will return 11223456 repeating only 1 and 2 and method3 (21) will return 2211. If the number is 0, return 0. You may assume that n is not negative

Answers

Answer 1

Answer:

Explanation:

The following is written in Java and creates only the method3 and returns a new method after doubling all of the 2's and 1's in the input.

public static int method3(int x) {

       int finalValue = 0;

       String number = String.valueOf(x);

       for (int i = 0; i < number.length(); i++) {

           if (number.charAt(i) == 1 || number.charAt(i) == 2) {

               finalValue += Integer.valueOf(number.charAt(i));

               finalValue += Integer.valueOf(number.charAt(i));

           } else {

               finalValue += Integer.valueOf(number.charAt(i));

           }

       }

       return finalValue;

   }


Related Questions

Here is the API for a robot library. // moves the robot forward function moveForward(); // turns the robot to the left function rotateLeft(); // turns the robot to the right function rotateRight(); // checks if a robot can move in any direction // direction {string} - the direction to be checked // return {Boolean} - true if the robot can move in that direction, otherwise returns false function canMove(direction); Which code segment will guarantee that the robot makes it to the gray square without hitting a wall or a barrier (black square)

Answers

Answer:

Option (A)

Explanation:

See attachment for options

From the options, the code segment of option (A) answers the question and the explanation is as follows:

I added a second attachment which illustrates the movement

function (solveMaze) {

moveForward(); ---- The robot moves up (to position 1)

moveForward(); ---- The robot moves up (to position 2)

rotateRight(); ---- The robot changes where it faces (however, it is still at position 2)

while(canMove("forward")) { moveForward(); } ---- This is repeated until the robot reaches the end of the grid (i.e. position 3 and 4)

rotateLeft(); ---- The robot changes where it faces (however, it is still at position 4)

moveForward(); ---- The robot moves up to the gray square

List 5 ways by which Artificial intelligence (AI) can be used to drive our business.​

Answers

Answer:

start a website

Explanation:

true

For our homework we have to listen__ a podcast​

Answers

Answer:

For our homework we have to listen to a podcast

Other Questions
Add the polynomials:2a+3b+5a-7b Explain your response Given that R7x + 7yFind x when y : 2 and R= 8Give your answer as a fraction in its simplest form.X = Overall the forth of july celebration was a blast there was food music and fireworks.correct the sentence Si Real Madrid gana el campeonato, reciben ____a. el trofeob. el puntajeC. el estadiod. el marcador Find the values of x, y, and z. Read the bottom before answering! Thank you! Anna, Brad, Carly, Deonte, and Elijah ran around a track aspart of a fundraiser for the schools math club. Anna ranfirst, and when she was tires, Brad ran. When Brad gottired, Carly ran, and so on. By the end of the fundraiser,they had run a total of 30 miles. Anna and Brad combinedran 12 miles.Brad and Carly combined ran 10.2 miles.Carly and Deonte combined ran 12 miles.Deonte and Elijah combined ran 12.3 miles.How far did each person run?Anna, Brad, Carly, Deonte, and Elijah ran around a track aspart of a fundraiser for the schools math club. Anna ranfirst, and when she was tires, Brad ran. When Brad gottired, Carly ran, and so on. By the end of the fundraiser,they had run a total of 30 miles. Anna and Brad combinedran 12 miles.Brad and Carly combined ran 10.2 miles.Carly and Deonte combined ran 12 miles.Deonte and Elijah combined ran 12.3 miles.How far did each person run?Note! Please do not put a troll answer, I really need help with this! You do not need to show work if you do not want to, I just need the overall answer! Thank you! I will mark brainliest Can someone help me answer these questions Blank is ____ rock in molten formWhat is this please help -6/7 (-3/8) answer?/ Hi Peeps!So have you gotton your TWO monologues ready for this week? If not, all I would like for you to do today is find them! Please refer to the Monologue assignment in my folder and go from there. Have them ready for tomorrow! For attendance purposes, and to recieve attendance/credit please answer the following questions by the end of today:1. 3 Elements in Musical Theater are 1. S--------- 2. D-------- 3. A------What do we call it when an actor poseses all three elements equally well? T_ip_ e Th_e_t! Ex: Hugh Jackman is definitaly a _________ ________. :) the Hawaiian Islands are a bunch of volcanoes formed as a result of a(an) Let's find +1418. First, write the addition so the fractions have denominator 8.Then add.=+1418=+818Lets find 1/4+1/8First, write the addition so the fractions have denominator 8.Then add. Plz help fast will mark brainliest Determine the slope given two points. Point 1 (6,-12) Point 2 (15,-3 What is the slope of the line that passes through the points (3, 4) and (-8, -2)? Factorise the following You are walking down a straight path in a park and notice there is another person walking some distance ahead of you. The distance between the two of you remains the same, so you deduce that you are walking at the same speed of 1.17 m/s. Suddenly, you notice a wallet on the ground. You pick it up and realize it belongs to the person in front of you. To catch up, you start running at a speed of 2.75 m/s. It takes you 10.5 s to catch up and deliver the lost wallet. How far ahead of you was this person when you started running A CD4 count that is below which amount classifies an infected person as having AIDS?A 200 cells per mm3B 800 cells per mm3C 400 cells per mm3D 600 cells per mm3 Whats this shape called?