Results 1 to 10 of 10
Thread: BlueJ Dividing Int Values
- 12-31-2013, 03:43 AM #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
}
- 12-31-2013, 03:49 AM #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]
YOUR CODE HERE
[/code]
to get highlighting and preserve formatting.
Do you have some specific questions about the part you are stuck on?If you don't understand my response, don't ignore it, ask a question.
- 12-31-2013, 03:52 AM #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(); } //====================== }
- 12-31-2013, 03:54 AM #4
Re: BlueJ Dividing Int Values
That looks a lot better.
Now what specific questions do you have?If you don't understand my response, don't ignore it, ask a question.
- 12-31-2013, 03:55 AM #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.
- 12-31-2013, 04:00 AM #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.
- 12-31-2013, 04:04 AM #7
Re: BlueJ Dividing Int Values
tell me in a message whether it is even
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));
Last edited by Norm; 12-31-2013 at 04:09 AM.
If you don't understand my response, don't ignore it, ask a question.
- 12-31-2013, 05:21 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.
- 12-31-2013, 01:47 PM #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.
If you have problems getting your code to work, post your code and ask some questions about it.If you don't understand my response, don't ignore it, ask a question.
- 12-31-2013, 06:36 PM #10
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
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,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads
-
Dividing numbers
By Pootis in forum New To JavaReplies: 3Last Post: 07-31-2012, 02:19 PM -
dividing the number range
By koneru_18 in forum New To JavaReplies: 1Last Post: 06-28-2011, 10:19 PM -
Dividing in java
By poop in forum New To JavaReplies: 4Last Post: 05-30-2011, 08:56 AM -
Dividing in Java
By hawaiifiver in forum New To JavaReplies: 19Last Post: 03-11-2011, 12:09 PM -
Dividing 3 items, please help.
By Quizzle23 in forum New To JavaReplies: 18Last Post: 02-24-2011, 07:42 AM
Bookmarks