0

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.

2
Contributors
5
Replies
6
Views
4 Years
Discussion Span
Last Post by NormR1
1

Can you post the code you are having problems with?

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

Votes + Comments
sure thing.
0
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 by gelmi: typo

1

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 by NormR1

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

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

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.