Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6602855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:55:40+00:00 2026-05-25T18:55:40+00:00

I am having some issues doing basic math with Java. I don’t know why

  • 0

I am having some issues doing basic math with Java. I don’t know why I am getting 0 as a result of multiplying n*n*n only in one case. (see below) I need this not to be zero because I have to divide timing/n*n*n to get that big O performance. Also if I can get that working the output may look like 0.00000 but I want to multiply that by like 100,000 just so I can see numbers and find any trends in performance.

You can see the values of n and timing in the first two number columns.

  • n is Integer
  • timing is Long

This is my output statement,

System.out.println(fmt.format("%20s %20d %20d %20d %20d %20d%n", "Alg. 1", n, timing, n*n*n, timing/(n*n), timing /*((double)timing/((double)n*Math.log((double)n)))*/));

My results,

 Alg. 1                  256                    4             16777216                    0                    4
 Alg. 1                  512                   22            134217728                    0                   22
 Alg. 1                 1024                  173           1073741824                    0                  173
 Alg. 1                 2048                 1362                    0                    0                 1362

Please keep in mind I need to perform this log math also. Any tips or fixes for that would also be appreciated!

Note: I am not dividing at all in the statement n*n*n and I am getting 0 in column four row four.

Can someone also please tell me how to get this to output decimal places that are accurate not just 0.000000. My new arithmetic is ((float)(timing/((long)n)*n*n)*100000. I am multiplying by 100000 as said above because I want to see something in the decimal places. I should be seeing 0.0159139 with this equation when n is 2048 and timing is 1362. I just see 0.000000 though. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:55:41+00:00Added an answer on May 25, 2026 at 6:55 pm

    20483 is 233 which overflows using 32-bit arithmetic. Use a long or a double to handle numbers this big.

    ((long) n) * n * n
    

    (Demo at ideone.com)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are having some issues getting SharePoint to work as we want it to.
I am using Fluent NHibernate and having some issues getting a many to many
again. Right now I'm having issues with some pretty basic functionality in PHP. I
I'm having some issues using rails validation on a form. What I'm doing is,
Ok, so I was having some issues getting rails setup and I'm very new
We've been having some issues with a SharePoint instance in a test environment. Thankfully
I have been having some issues with LINQ-To-SQL around memory usage. I'm using it
I'm having some issues with producing an int matrix without creating memory leaks. I
I am having some issues with using the OrderBy extension method on a LINQ
I'm having some inheritance issues as I've got a group of inter-related abstract classes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.