Hi: I'm trying to solve a question as it states: "Create a program which determines if a given number a is a common divisor of two other numbers num1 and num2." I am 100% beginner to Java and just started a couple days ago, so most terms discussed feel quite foreign to me, and so i usually need a little extra explaining. This is what I have come up with so far, even though I know it is not right, as i get errors.

 * AWT Sample application
 * @author 
 * @version 1.00 09/09/10
public class Common_divisor {
    public static void main(String[] args) {
     int a; 
     int num2; 
     int num1; 
     if (a % num2 = 0 && a % num1 = 0 )
     System.out.println("Common Divisor");
     System.out.println("Not Common Divisor");

Above is what i have come up with so far. I'm not sure which is the best way going about answering the question, be it by attaching a scanner, using random numbers, etc.

Your help is always appreciated, thanks a ton in advance.

You need to give values to your variables:

int a; 
     int num2; 
     int num1;

I suggest you enter put some values inside the code in order to test if the logic is correct:

int a = 2; 
     int num2; = 4 
     int num1 = 10;

And then use the Scanner class to get the input from the keyboard:

Scanner scan = new Scanner(System.in);
if (scan.hasNextInt() ) {
   a = scan.nextInt();
} else {
   System.out.println("No number given");

Also read this first

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