Hi, can someone help me about this problem or suggest some pseudocode?
if i input this numbers

12 ,24, 100
output should be

YES, YES, YES
i'm confused in writing the solution in code.

Can you post the code you are having problems with?

pseudo code:
begin loop
read number
print "YES"
end loop

Comments
sure thing.
import java.util.Scanner;

public class Divisor {
    public static void main (String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Number: ");
        int n = in.nextInt();
        int counter = 0;
        for (int i = 1; i <=n; i++) {
            if (n % i == 0) {
                counter++;

            }
            System.out.println(counter);
        }
    }
}

what is in my mind is to get the divisors then add them up. Then insert an if statement. The problem is i don't know how to add them up. :)

Edited 4 Years Ago by gelmi: typo

how to add them up.

After the new number is obtained, add it to the variable that is to accumulate the total:
total = total + newNumber;

or shorthand way:
total += newNumber;

Can you post pseudo code for what you are trying to do? Make a list of the steps the code should take to do what you want done. Each step in the list should be as simple as possible.

Edited 4 Years Ago by NormR1

Comments
if i will put total += (what would i put here?)

hi again, how do i add the divisors?
i tried doing that it gave me answers, but wrong :) i hope you can still help me.

total += newNumber

Please post the code you are having problems with and ask your questions about it.
I don't know what you mean by: how do i add the divisors?

This article has been dead for over six months. Start a new discussion instead.