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 9144865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:22:25+00:00 2026-06-17T10:22:25+00:00

I’m stuck in my program. I need help using a function in the main

  • 0

I’m stuck in my program. I need help using a function in the main method. So far I have this:

    double x, y;
    char op;

    System.out.print("X: ");
    x = keyboard.nextDouble();
    System.out.print("Y: ");
    y = keyboard.nextDouble();

    System.out.print("Enter Operation: ");
    op = keyboard.next().charAt(0);

    do
    {   
        if (op == '+');
            System.out.print("..");

    }
    while (op != 'q');

    System.out.print("Bye!");
}

public static double sum (double x, double y)
{
    double sum = 0;
    sum = (x + y);

    return sum;
}
public static double minus (double x, double y)
{
    double minus = 0;
    minus = (x - y);

    return minus;
}
public static double multiply (double x, double y)
{
    double multiply = 0;
    multiply = (x * y);

    return multiply;
}
public static double divide (double x, double y)
{
    double divide = 0;
    divide = (x/y);

    return divide;
}

For the “if statement” I want to use the functions. If the operation is ‘+’ then it would use the sum function to add x and y. But how do I type it in the “if statement”?
Sorry. It’s my second programming class so I’m still learning.

  • 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-17T10:22:27+00:00Added an answer on June 17, 2026 at 10:22 am

    You call another function something like this:

    double output = sum(1,3);
    

    Even more generally, it goes something like this:

    OutputType VariableToHoldOutput = MethodName(Parameter1, Parameter2, etc);
    

    With the output being optional to store. If the output type is void, you cannot even store it. That would result in something like this

    MethodName(Parameter1, Parameter2, etc);
    

    ALSO, an if statement is not followed by a semicolon. The way you have it is equivalent to:

    if (op == '+')
    {
        ;
    }
    System.out.print("..")
    

    You probably want something more like:

    if(op == '+')
    {
        double output = sum(X,Y);
        System.out.print("Output = " + output);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I need a function that will clean a strings' special characters. I do NOT
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.