Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2010
    Posts
    1
    Rep Power
    0

    Default Problem regarding multiplication

    Java Code:
    public class Savings
    {
    	public static void main(String [] args)
    	{	int p=1000,r=4;int a;
    
    		int x=(int)Math.pow((1+r),10); //Output -- 9765625
    		a=p*(int)Math.pow((1+r),10); // Output -- 1175690408
    		System.out.println(x+"\n"+a);
    	}
    
    }
    its just a simple code. but am having trouble with it

    9765625 *1000 == 9765625000 isnt it? then why is it showing such an output?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by javanewbie1234 View Post
    Java Code:
    public class Savings
    {
    	public static void main(String [] args)
    	{	int p=1000,r=4;int a;
    
    		int x=(int)Math.pow((1+r),10); //Output -- 9765625
    		a=p*(int)Math.pow((1+r),10); // Output -- 1175690408
    		System.out.println(x+"\n"+a);
    	}
    
    }
    its just a simple code. but am having trouble with it

    9765625 *1000 == 9765625000 isnt it? then why is it showing such an output?
    ... because an int has four bytes and 9765625000 doesn't fit in four bytes.

    kind regards,

    Jos

Similar Threads

  1. Multiplication Table
    By SwEeTAcTioN in forum New To Java
    Replies: 4
    Last Post: 02-24-2010, 04:11 AM
  2. Multiplication table quiz
    By wolfy101 in forum New To Java
    Replies: 1
    Last Post: 11-16-2009, 06:29 AM
  3. Multiplication table
    By rjones215 in forum New To Java
    Replies: 3
    Last Post: 10-19-2009, 04:34 PM
  4. Help with Multiplication
    By phil028 in forum New To Java
    Replies: 1
    Last Post: 12-06-2007, 07:39 PM
  5. Help with multiplication table
    By Albert in forum New To Java
    Replies: 1
    Last Post: 07-10-2007, 04:44 PM

Posting Permissions

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