Dynadot โ€” .com Registration $8.99

[Resolved] Java: Signatures and Method HELP

Spaceship Spaceship
Watch

zk0

Established Member
Impact
3
Java: Signatures and Method HELP

I need help with this Java code!

I want to count the numbers in the main using the code in the class MyMath. But I dont really understand how? This is what I have done so far but it's not correctly performed and it doesnt count the last line from the main:

Code:
System.out.println(MyMath.add(123, 6.54));

THE CODE:

Code:
package your_username;

public class Program
{
	public static void main(String[] args)
	{
		int intSum = MyMath.add(123, 456);
		System.out.println(intSum);
		
		double doubleSum = MyMath.add(9.87, 6.54);
		System.out.println(doubleSum);

		System.out.println(MyMath.add(123, 6.54));
	}
}

class MyMath
{

	public static int add(int i, int j) {
		System.out.println(">>> metoden med signaturen add(int, int) har anropats <<<");
		return (123+456); // 
	}

	public static double add(double d, double e) {
		System.out.println(">>> metoden med signaturen add(double, double) har anropats <<<");
		return (9.87+6.54); 
	}

}

Thanks for any help in advance!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
When you say it doesn't count the last line, what do you mean exactly? Do you mean it's not doing anything, or it's giving you the wrong answer?

I'm assuming you mean the latter and I'm assuming it's because the return values in your class have been hard coded...
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back