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

  • SEARCH
  • Home
  • 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 8345439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:40:20+00:00 2026-06-09T06:40:20+00:00

I am using Math.PI in my example, so it is a double. It is

  • 0

I am using Math.PI in my example, so it is a double. It is a simple code but there is a bit I am not sure how to do:

I want the code to calculate the fundamental period X of a sin or cos function with a multiplier value a given by the user. The n value is initialized at n=1 and is an integer value.

If the result of (2 * pi * n)/a = X is lower than pi then n should increment, and it should keep going until that number is a multiple of pi, then print the result.

Just to clarify: a is a multiplier of x which goes in the function sin or cos like this:

cos(ax)

sin(ax)

The bit I am having the trouble with is working out whether the number is a multiple of pi (provided it’s already greater than pi, that is).

This is about as far as I got and it’s incomplete.

 public void printSinusoidalPeriod(double multiplier /* this would be `a` */){

    double pi=Math.PI;

    double p = (2 * pi * (double) n) / multiplier;

    while(p<pi){

        if(n%pi==0){

            n=n+1;
            System.out.println(n);
                            p = (2 * pi * (double) n) / multiplier;
        }
    }
    p= (double)Math.round(p * 100) / 100;


    System.out.println("period of function is = " + p + " and n = " + n);
}

It seems like it’s not going into the if statement and getting caught in the while loop

  • 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-06-09T06:40:21+00:00Added an answer on June 9, 2026 at 6:40 am

    Ok here’s how I did it in the end, with the help of the suggestions here.

    public void printSinusoidalPeriod(double a){
    
        double pi=Math.PI;
        double p=m*pi;
    
        while(n<a/2){
    
            if((double)Math.round((n*pi)%pi)!=0.01){
    
                n=n+1;
    
                m = (int) Math.round(((2 * (double) n) / a));
                p= (double)Math.round(m * pi * 100) / 100;
                p=p*n;
    
            }
        }
        System.out.println("period of function is = " + p + " and n = " + n);
        System.out.println("Check: p/n = " + p/n);
    }
    

    Please let me know if you can spot any problems with the logic. I have not gone through many possibities yet, but the ones I did, looked okay to me.

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

Sidebar

Related Questions

Am using Math.round and I am finding that it will not return me any
I am trying to do a little bit of math using dates in PHP.
When using a DenseMatrix from Math .NET, and I want to access the second
I have the following code. #include math.h // for sqrt() function #include <iostream> using
Is it possible to concatenate after using a Math equation? I have a simple
...is it possible? For example, can I add this simple function... public static double
All began with these simple lines of code: string s = 16.9; double d
For example, I would like to do some manipulation and methods using the Math
I have written simple math function plotter in C# using Patrick Lundin´s Math free
I'm using sqrt() function from math library, when I build for 64 bit using

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.