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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:35:31+00:00 2026-06-06T00:35:31+00:00

i am a beginner at java language and i use text pad. i have

  • 0

i am a beginner at java language and i use “text pad”. i have a problem with my simple program. my task is to input 2 values and show the “sum”,”difference”,”product” and “quotient” altogether. (simple right?) in which , here below is the class that supposed to be doing the job of arithmetic. in which is “correct” as i compiled.

public class mathclass
{

    int x;
    int y;
    int total;


    void add ()
    {
        total = x+y;
    }

    void sub ()
    {
        total = x-y;
    }

    void multi ()
    {
        total = x*y;
    }

    void div ()
    {
        total = x/y;
    }

}

And here is the main program that supposed to be the input and output of the program.
my problem here is that i can’t pass the 2 variables (num1 and num2) to “mathclass”
i did research on how to pass 2 variables to a another class. but there is nothing same to mine that i have. i did use some like the putting “private or public” on the variables.
my teacher said to use the BufferedReader for input. and i am having a hard time how to get this program right. (sorry if i had wrong english(if i am wrong. ))

import java.io.*;
public class mathmain
{

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[]args)throws IOException
    {


        mathclass math1 = new mathclass();

        System.out.print("Enter 1st Number :");
        num1 = Integer.parseInt(br.readLine());
        System.out.println(" ");

        System.out.print("Enter 2nd Number :");
        num2 = Integer.parseInt(br.readLine());
        System.out.println(" ");

        System.out.println(" ");
        System.out.println(" ");
        System.out.println(" ");

        math1.add();
        {
            System.out.print("Sum : ");
            System.out.println(math1.total);
        }
        System.out.println(" ");
        math1.sub();
        {
            System.out.print("Difference : ");
            System.out.println(math1.total);
        }
        System.out.println(" ");

        math1.multi();
        {
            System.out.print("Product : ");
            System.out.println(math1.total);
        }
        System.out.println(" ");
        math1.div();
        {
            System.out.print("Quotient : ");
            System.out.println(math1.total);
        }
    }
}
  • 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-06T00:35:32+00:00Added an answer on June 6, 2026 at 12:35 am

    It’s really not clear what you’re trying to do here. (Why doesn’t add take two arguments for instance?)

    Perhaps your after something like this:

    // Set up arguments
    math1.x = num1;
    math1.y = num2;
    
    // Perform the add.
    math1.add();
    // {                <-- brace completely useless.
    
    // Print the result
    System.out.print("Sum : ");
    System.out.println(math1.total);
    // }                <-- brace completely useless.
    

    However, I would encourage you to use return values and use parameters:

    class MathClass {
    
        public int add(int a, int b) {
            return a + b;
        }
    
        ...
    }
    

    and then use the class like

    int sum = math1.add(num1, num2);
    
    System.out.println("Sum: " + sum);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a beginner in Java programming language, and I have a problem that I
I'm a beginner in Java, and NetBeans. I'm trying to make a simple program
Am Beginner to java.I have a small doubt while i am developing an application
I have a very basic knowledge of the Java language and how it works
Most high-level languages (Python, Ruby, even Java) use pass-by reference. Obviously, we don't have
I am a beginner in Java and is learning to use array. I understand
Hi I am beginner in java and my program has 4 for loops: my
i have a java beginner question: Parent.print() prints hallo in the console, but also
I'm a complete beginner trying to learn Java as my first language. When I'm
I'm a Java beginner. I already created a simple GUI application that display will

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.