Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Set up a new project in your IDE with a Main class. In your Main class, creatte a nextHappyNum method. int nextHappyNum(int num) 1. For

Set up a new project in your IDE with a Main class. In your Main class, creatte a nextHappyNummethod.

int nextHappyNum(int num)

1. For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps where in each step number is replaced by sum of squares of its digits. That is if we start with Happy Number and keep replacing it with digits square sum, we reach 1 (7 -> 49 -> 97 -> 130 -> 10 -> 1). For example,

----------------------------------

Input: 8 Output: 10 Input: 3 Output: 7 Input: 0 Output: 1 Input: 10 Output: 13

----------------------------------

2. In your Main class, creatte a decodeString method.

String decodeString(String s)

An encoded string (s) is given, the task is to decode it. The pattern in which the strings were encoded were as follows original string:abbbababbbababbbab encoded string :"3[a3[b]1[ab]]".

For example:

----------------------------------

Input: 1[b] Output: b Input: 3[b2[ca]1[d]] Output: bcacadbcacadbcacad

----------------------------------

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Cost Management Measuring Monitoring And Motivating Performance

Authors: Leslie G. Eldenburg, Susan Wolcott, Liang Hsuan Chen, Gail Cook

2nd Canadian Edition

1118168879, 9781118168875

More Books

Students also viewed these Programming questions