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 8726243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:12:31+00:00 2026-06-13T08:12:31+00:00

Study question is to find the digit root of a already provided number. The

  • 0

Study question is to find the digit root of a already provided number. The teacher provides us with the number 2638. In order to find the digit root you have to add each digit separately 2 + 6 + 3 + 8 = 19. Then you take the result 19 and add those two digits together 1 + 9 = 10. Do the same thing again 1 + 0 = 1. The digit root is 1.

My first step was to use the variable total to add up the number 2638 to find the total of 19. Then I tried to use the second while loop to separate the two digits by using the %

I have to try and solve the problem by using basic integer arithmetic (+, -, *, /).
1.Is it necessary and or possible to solve the problem using nested while loops?
2.Is my math correct?
3. As I wrote it here it does not run in Eclipse. Am I using the while loops correctly?

import acm.program.*;


public class Ch4Q7 extends ConsoleProgram {
   public void run(){
      println("This program attempts to find the digit root of your number: ");

      int n = readInt("Please enter your number: "); 

      int total = 0;

      int root = total;


      while (n > 0 ){
        total = total + (n %10);
    n = (n / 10);

    }   

   while ( total > 0 ){
     root = total; 
     total = ((total % 10) + total / 10); 
    }


     println("your root should be " + root);
}

}

  • 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-13T08:12:32+00:00Added an answer on June 13, 2026 at 8:12 am

    I think it does run, but just a bit too much 🙂

    total = ((total % 10) + total / 10); 
    

    can’t converge to 0. Also, your program as it is will only handle very specific cases. As others pointed out, this can be solved recursively, but also with just a double loop. A succession of loops like you tried won’t work.

    Try this (on input vars are the same as in your program, it’s really a plugin replacement for your two loops):

        do {
            while (n > 0) {
                total = total + (n % 10);
                n = (n / 10);
            }
            n = total;
            total = 0;
        } while (n > 9);  // need at least 1 more loop
    

    After this loop n will contain the root number.

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

Sidebar

Related Questions

I have this question from the Zend PHP study guide and can't find a
Study guide question: I have no idea what the difference is between writing it
My question is deceptively simple, but I have lost several hours of study trying
I was given this question on my study guide for a test I have
I have started to study Three20 and I have a simple question about TT_RELEASE_SAFELY
I'm starting to study GWT now, and have a very general question, I could
I have the following question, recently I started with the study of Android and
I have a question. My case study is that I have two big SQLite
I just started to study the android so im asking such a simple question.
I have read this question , but I couldn't create a full example: class

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.