I am needing to make a program add and multiple from two different entries and display the total on a different line. I am needing the syntax on how to add and multiply. A web reference page would be good as well. All I have is two classes at this time, main and subclass. As you can see from my question I am new. Your assistance is appreciated.

Recommended Answers

All 2 Replies

ClassA:

public static double add(double a, double b) {
   return a+b;
}

Main

import java.util.Scanner;

..................

Scanner scan = new Scanner(System.in);

// print message for user to enter input
String strA = scan.nextLine();
double a  = Double.parseDouble(strA);

// print message for user to enter input
String strB = scan.nextLine();
double b  = Double.parseDouble(strB);

double res = ClassA.add(a, b);

// print result

Thank you for the information. I'll give it a try and see if can work for me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.