# Thread: BlueJ Dividing Int Values

1. Member
Join Date
Dec 2013
Posts
12
Rep Power
0

## BlueJ Dividing Int Values

I don't know how to do Exercise 4.26* Write an application program that asks the user for two int values and then announces whether one evenly divides the other (using %). This is my code so far at the bottom, but I am stuck on the rest. What should I do?

public static void main (String[ ] args)
02
{
03

04
Scanner sc = new Scanner(System.in);
05

06
int firstNumber;
07
System.out.println("Input a number");
08
firstNumber = sc.nextInt();
09

10
int secondNumber;
11
System.out.println("Input another number");
12
secondNumber = sc.nextInt();
13

14

15

16

17

18
} //======================
19
}

2. ## Re: BlueJ Dividing Int Values

Please clean up the posted code (get rid of the numbers) and wrap your code with code tags:
[code]
[/code]
to get highlighting and preserve formatting.

Do you have some specific questions about the part you are stuck on?

3. Member
Join Date
Dec 2013
Posts
12
Rep Power
0

## Re: BlueJ Dividing Int Values

Here is my code.

Java Code:
```public static void main (String[ ] args)
{

Scanner sc = new Scanner(System.in);

int firstNumber;
System.out.println("Input a number");
firstNumber = sc.nextInt();

int secondNumber;
System.out.println("Input another number");
secondNumber = sc.nextInt();

}  //======================
}```

4. ## Re: BlueJ Dividing Int Values

That looks a lot better.

Now what specific questions do you have?

5. Member
Join Date
Dec 2013
Posts
12
Rep Power
0

## Re: BlueJ Dividing Int Values

My question is what should I add to the code so that BlueJ can mathematically divide an answer and tell me in a message whether it is even or not.

6. Member
Join Date
Dec 2013
Posts
12
Rep Power
0

## Re: BlueJ Dividing Int Values

Can you fix my code for me so it is correct? Thanks.

7. ## Re: BlueJ Dividing Int Values

tell me in a message whether it is even
The common way to test if a number is even is to use the modulus operator (%) with 2 and test if the result is 0. (4%2) = 0
The result will be 1 if the number is odd.

Try a few test statements and print the results to see how it works. For example:
Java Code:
`System.out.println("4 % 3 = "+ (4%3));`
Change the 4 and 3 to different values, compile, execute and look at the results.
Last edited by Norm; 12-31-2013 at 04:09 AM.

8. Member
Join Date
Dec 2013
Posts
12
Rep Power
0

## Re: BlueJ Dividing Int Values

So is this all that I have to put in the code to make it correct? If not please give me the whole thing with corrections.

9. ## Re: BlueJ Dividing Int Values

The code I posted was an example for you to try to understand how the % operator works.

You need to figure out what the program needs to do to solve the assignment. Then write the code for your program.

10. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,738
Rep Power
10

## Re: BlueJ Dividing Int Values

I noticed you included BlueJ in your subject line. There are Java errors and there are IDE errors. This is a Java error which applies regardless of the IDE of choice. Just so you know the difference. And the reason I mention it is that some folks might ignore your post if they aren't familiar with BlueJ.

Regards,
Jim