Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8674969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:50:11+00:00 2026-06-12T19:50:11+00:00

So I have been tasked with writing a program that determines if a number

  • 0

So I have been tasked with writing a program that determines if a number is insipid or not. Meaning, if you take a number:
57 for example, and you add the square of each digit, 5*5 + 7*7, that is now the new number:74. And you keep doing that until you either get 58 which means the number is NOT insipid, or you get 1, meaning the number is. 58 will just repeat a sequence that always ends back on 58.

So I wanted to attempt it with some basic recursion but perhaps I misunderstand the use of recursion here.

Here are the two relevant methods I wrote:

public static boolean insipid(int num){

    int dig1 = 0, dig2 = 0, dig3 = 0; // num = 159 for example, dig1 would be 1. Default is 0 in case of a 2 digit number, dig1*dig1 = 0
    if(num == 58){ //The number is not insipid
        return false;
    }
    if(num == 1){ // the number is insipid
        return true;
    }

    if (num < 10){
        insipid(num * num);
    }
    if(num>99){
        dig1 = (int)(num / 100);
        dig2 = (int)((num - 100)/10);
        dig3 = num - (((int)(num / 10))*10);
        insipid(squaresum(dig1,dig2,dig3));
    }
    else{
        dig2 = (int)(num/10); //the 10s place
        dig3 = num - (((int)(num/10)) * 10); // the 1's place
        insipid(squaresum(dig1, dig2,dig3)); //dig1 = 0 so I just pass it along with it.
    }
}

public static int squaresum(int dig1, int dig2, int dig3){
    //Returns the sum of three digits squared.
    return (dig1 * dig1) + (dig2 * dig2) + (dig3 + dig3);
}

It gives me an error saying that Insipid() must return a boolean whenever I supply it a number. But I know for any number given it will always either eventually resolve to 58 or 1. So shouldn’t true or false always eventually be returned so a boolean is returned and the error is invalid? Obviously this is not the case, but how I see it. Is it the use of the recursion here that is invalid?

Also, if you have any suggestions on how I might clean this up I wouldn’t mind harsh criticism, my java is not very good.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:50:12+00:00Added an answer on June 12, 2026 at 7:50 pm

    Update you insipid as below. A method declared with return must return values in all cases. Your method doesn’t return any value if it reach second else i.e. if number is anything other than 1 & 58.

    public static boolean insipid(int num){
      boolean returnValue = false;
      if(num == 58){ //The number is not insipid
       //do nothing
      } if(num == 1){ // the number is insipid
        returnValue = true;
      }else{
        int dig1 = 0, dig2 = 0, dig3 = 0; // num = 159 for example, dig1 would be 1. Default is 0 in case of a 2   digit number, dig1*dig1 = 0
        if (num < 10){
            returnValue = insipid(num * num);
        }
        else if(num>99){
            dig1 = (int)(num / 100);
            dig2 = (int)((num - 100)/10);
            dig3 = num - (((int)(num / 10))*10);
            returnValue = insipid(squaresum(dig1,dig2,dig3));
        }
        else{
            dig2 = (int)(num/10); //The 10s place
            dig3 = num - (((int)(num/10)) * 10); //the 1s place
            returnValue = insipid(squaresum(dig1, dig2,dig3)); //dig1 = 0 so I just pass it along with it.
        }
      }
      return returnValue ;
    }
    

    Please Note: I just tried to answer your issue regarding return issue ONLY.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not really familiar with Joomla but I have been tasked with writing
I've been tasked with writing a WCF service. (have not done this before.) I've
I have been tasked with writing a program which will run a set of
I have been tasked with writing a stored procedure that takes a user specified
In my MIPs Assembly Programming class I've been tasked with writing a program that
I have been tasked with writing an xsd, for an xml file format that
I have been tasked with creating a program that will generate an amortization schedule.
I have been writing a program that is quite complex compared to what I
I have been tasked to create a GUI program that is to work with
I have been tasked with writing an installer with a silverlight out of browser

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.