Results 1 to 10 of 10
  1. #1
    bluejpersona is offline Member
    Join Date
    Dec 2013
    Posts
    12
    Rep Power
    0

    Default 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. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default 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.

  3. #3
    bluejpersona is offline Member
    Join Date
    Dec 2013
    Posts
    12
    Rep Power
    0

    Default 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. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default 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.

  5. #5
    bluejpersona is offline Member
    Join Date
    Dec 2013
    Posts
    12
    Rep Power
    0

    Default 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. #6
    bluejpersona is offline Member
    Join Date
    Dec 2013
    Posts
    12
    Rep Power
    0

    Default Re: BlueJ Dividing Int Values

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

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    bluejpersona is offline Member
    Join Date
    Dec 2013
    Posts
    12
    Rep Power
    0

    Default 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. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default 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.

  10. #10
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,023
    Rep Power
    6

    Default 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
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Dividing numbers
    By Pootis in forum New To Java
    Replies: 3
    Last Post: 07-31-2012, 02:19 PM
  2. dividing the number range
    By koneru_18 in forum New To Java
    Replies: 1
    Last Post: 06-28-2011, 10:19 PM
  3. Dividing in java
    By poop in forum New To Java
    Replies: 4
    Last Post: 05-30-2011, 08:56 AM
  4. Dividing in Java
    By hawaiifiver in forum New To Java
    Replies: 19
    Last Post: 03-11-2011, 12:09 PM
  5. Dividing 3 items, please help.
    By Quizzle23 in forum New To Java
    Replies: 18
    Last Post: 02-24-2011, 07:42 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •