Results 1 to 4 of 4
  1. #1
    leoshiner is offline Member
    Join Date
    Oct 2010
    Posts
    28
    Rep Power
    0

    Default modulus value keeps returning a zero value

    Hi I am trying to write a basic programme that returns a modulus value but it keeps returning a value of zero no matter what values I enter,I would greatly appreciate it if someone could point out what I am doing wrong.here is the code.

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package calculatemodulus;

    import javax.swing.JOptionPane;

    /**
    *
    * @author Leon
    */
    public class CalculateModulus {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    String numStr1,numStr2;

    int num1,
    num2,
    modulus;

    numStr1=JOptionPane.showInputDialog("Enter first number");
    numStr2=JOptionPane.showInputDialog("Enter second number");

    num1= Integer.parseInt(numStr1);
    num2= Integer.parseInt(numStr1);

    modulus= num1%num2;



    JOptionPane.showMessageDialog(null,"The modulus is" +modulus);

    System.exit(0);

    }

    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Look very carefully here:
    Java Code:
          num1 = Integer.parseInt([color="red"]numStr1[/color]);
          num2 = Integer.parseInt([color="red"]numStr1[/color]);

  3. #3
    leoshiner is offline Member
    Join Date
    Oct 2010
    Posts
    28
    Rep Power
    0

    Default

    oh I'm an awful idiot,thanks for your help

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Returning Value from a method
    By Mirix in forum New To Java
    Replies: 12
    Last Post: 06-01-2010, 09:48 PM
  2. Returning An Array
    By elektronika in forum New To Java
    Replies: 2
    Last Post: 12-07-2009, 03:43 PM
  3. read() is not returning -1
    By Mewes in forum Networking
    Replies: 0
    Last Post: 11-30-2009, 10:46 PM
  4. returning arrays
    By cjohnson412 in forum New To Java
    Replies: 4
    Last Post: 11-25-2008, 01:30 PM
  5. [SOLVED] Modulus/Remainder results
    By antgaudi in forum New To Java
    Replies: 9
    Last Post: 10-13-2008, 03:49 AM

Posting Permissions

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