NameSilo

[Resolved] Java: Signatures and Method HELP

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back