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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:01:57+00:00 2026-06-13T03:01:57+00:00

So my assignment is to find all the magic numbers within a range of

  • 0

So my assignment is to find all the “magic numbers” within a range of numbers (input by the user). A magic number is a number whose factors (except itself) sums up to that number. So 6 would be a magic number because it’s factors besides itself are 1,2 and 3 which sum up to 6. I have stared at this code for some time now and cannot figure out for the life of me why it won’t print out the magic number. Any help would be appreciated.

public class MagicNumber {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.print("What is the top of the range?");
    int range = IO.readInt();
    if (range <= 0 ) {
        IO.reportBadInput();
    }
    int sumOfFactors = 0;
    for (int i = 1 ; i <= range ; i++) {
        for (int m = 1 ; m < i; m++) {
            if (i % m == 0) {
                sumOfFactors = sumOfFactors + m;
            }
            if (sumOfFactors == i) {
                System.out.println(i);
                    }
            }
        }
    }
}
  • 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-13T03:01:59+00:00Added an answer on June 13, 2026 at 3:01 am

    You are testing whether sumOfFactors == i while you are still summing factors. You need to move that outside the m loop. Then you need to set sumOfFactors to 0 before starting the m loop each time through the i loop, not just once at the start of the looping.

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

Sidebar

Related Questions

My class assignment is to write a program that has the user input a
My assignment problem is to find all non-overlapping occurences of a substring in a
My boss have given me assignment to find how a web based application developed
This is part of a homework assignment. I've got several questions asking find the
I'm working on an assignment for class and the question asks to find matches
Okay I have an assignment to find the Kth smallest element in the list
I have been looking all over google to find some answers to my questions
The assignment, for my data structures class, is to find the shortest path from
This is a homework assignment, just for all that want to know. I'm writing
I have a homework assignment to write a multi-threaded sudoku solver, which finds all

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.