Question

don't use system.exit() please

don't use system.exit() please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java code for above problem

class Main
{
   public static void main(String args[])
   {
       String str="qwwwwwwwwweeeeerrtyyyyyqqqqwEErTTT";
       System.out.println("Original string: "+str);
       String encoded_str=encode(str);
       System.out.println("Encoded string: "+encoded_str);
       String decoded_str=decode(encoded_str);
       System.out.println("Decoded string: "+decoded_str);
   }
   public static String decode(String str)
   {
       if(str.length()==0)
           return "";
       char ch=str.charAt(0);
       if(Character.isDigit(ch))
       {
           int count=ch-'0';
           String temp=get_str(str.charAt(1),count);
           return temp+decode(str.substring(2));
       }
       return ch+decode(str.substring(1));
   }
   public static String get_str(char ch,int count)
   {
       if(count==0)
           return "";
       return ch+get_str(ch,count-1);
   }
  
  
   public static String encode(String str)
   {
       String encoded_str="";
       int len=str.length();
       int i=0;
       while(i<len)
       {
           int j=i+1;
           while(j<len && str.charAt(j)==str.charAt(i))
               j++;
           int count=j-i;
           if(count>1)
               encoded_str+=String.valueOf(count);
           encoded_str+=str.charAt(i);
           i=j;
       }
       return encoded_str;
   }
}

Sample output

Original string: WWWWWWWWWWeeeeerrtyyyyyqqqqwEETIT Encoded string: q9w5e2rt5y4qw2Er3T Decoded string: WWWWWWWWWWeeeeerrtyyyyy

Mention in comments if any mistakes or errors are found. Thank you.

Add a comment
Know the answer?
Add Answer to:
don't use system.exit() please
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • don't use System.exit() please

    don't use System.exit() please

  • use your own words, don't copy and paste, don't use handwriting, please. i need references please...

    use your own words, don't copy and paste, don't use handwriting, please. i need references please Discuss the applications of Binary Logistic Regression in Clinical Research using the case study given in the(Application of Binary Logistic Regression in Clinical Research) in a brief manner with a maximum length of two pages use your own words, don't copy and paste, don't use handwriting, please. i need references please use your own words, don't copy and paste, don't use handwriting, please. i...

  • Please, i need Unique answer, Use your own words (don't copy and paste). *Please, don't use...

    Please, i need Unique answer, Use your own words (don't copy and paste). *Please, don't use handwriting. Please, i need Unique answer, Use your own words (don't copy and paste).Please, i need Unique answer, Use your own words (don't copy and paste).Please, i need Unique answer, Use your own words (don't copy and paste).Please, i need Unique answer, Use your own words (don't copy and paste).Please, i need Unique answer, Use your own words (don't copy and paste).Please, i need...

  • use your own words, don't copy and paste, don't use handwriting, please. i need references please...

    use your own words, don't copy and paste, don't use handwriting, please. i need references please * Select an environmental health problem, in Saudi community. Outline of Environmental health report (1-2 pages) 1 The environmental health problem 1.1 What is the problem ? 1 point 1.2 Where is that problem? I point 1.3 When the problem happened? 1 point 2 Causes of the environmental health problem 2 points 3 Health effects of the problem Use references , 2 points 4...

  • ** use your own words, don't copy and paste, don't use handwriting, please. i need your...

    ** use your own words, don't copy and paste, don't use handwriting, please. i need your references URL Link please** ** use your own words, don't copy and paste, don't use handwriting, please. i need your references URL Link please** Q: Find out a food technical regulation and standards for any selected food items in Kingdom of Saudi Arabia (example- pickled fruits, pickled cucumber). Discuss the health effects about the food additives used on them   // i need more details and...

  • Please, i need Unique answer, Use your own words (don't copy and paste) *Please, don't use...

    Please, i need Unique answer, Use your own words (don't copy and paste) *Please, don't use handwriting. * i need References APA style Q1. What are the General purposes of communication?

  • Please, i need Unique answer, Use your own words (don't copy and paste). *Please, don't use...

    Please, i need Unique answer, Use your own words (don't copy and paste). *Please, don't use handwriting. How do Internet technologies help companies in building a customer-focused business?

  • Please, i need Unique answer, Use your own words (don't copy and paste). *Please, don't use...

    Please, i need Unique answer, Use your own words (don't copy and paste). *Please, don't use handwriting. * i need References APA style . What are the major food groups for diet? (1 Point)

  • use your own words, don't copy and paste, don't use handwriting, please. i need references please...

    use your own words, don't copy and paste, don't use handwriting, please. i need references please * Select an environmental health problem, in Saudi community. please DON'T talk about Desertification Outline of Environmental health report (1-2 pages) 1 The environmental health problem 1.1 What is the problem ? 1.2 Where is that problem? 1.3 When the problem happened? 2 Causes of the environmental health problem 3 Health effects of the problem Use references , 4 Solutions / mitigation measures Use...

  • use your own words, don't copy and paste, don't use handwriting, please. i need references please...

    use your own words, don't copy and paste, don't use handwriting, please. i need references please * Select an environmental health problem, in Saudi community. please DON'T talk about Desertification Outline of Environmental health report (1-2 pages) 1 The environmental health problem 1.1 What is the problem ? 1.2 Where is that problem? 1.3 When the problem happened? 2 Causes of the environmental health problem 3 Health effects of the problem Use references , 4 Solutions / mitigation measures Use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT