Jump to content

Need Help with Creating Java Methods

IvanSnipedYu
Go to solution Solved by HPWebcamAble,
Just now, IvanSnipedYu said:

It gives me a compilation error. I just noticed the thing you were pointing out. I changed it but now I get no output.

You mean mean it doesn't tell you the result?

You need to ask it to print to the console.

 

Here's the method to do that:

system.out.println( "<something to print>" )

 

I'm trying to learn creating java methods rn but for some reason I can't get something like this to work. Can someone please explain to me what I did wrong and how I can fix it.

 

import java.util.Scanner;
public class HW06P01 {

	public static int findTerm(int n){
		int result;
		result = ((n(7*n-3))/5);
		return result;
	}
	
	
	public static void main(String[] args) {
		int a = 1;
		findTerm(a);

	}

}

 

| i7 4790k | H100i | 16GB (8x2) Corsair Vengence | EVGA GTX 780 SC | ASUS Z97 Sabertooth Mark I | Samsung 840 120GB | WD 2TB Green x2 | Rosewill Hive 750W | 

Link to comment
Share on other sites

Link to post
Share on other sites

What's wrong exactly?

 

Just guessing, I'd say this:

result = ((n(7*n-3))/5);

Needs another multiplication symbol, like this:

result = ((n*(7*n-3))/5);

 

i7 4790k | MSI Z97S SLI Krait Edition | G.Skill Ripjaws X 16 GB | Samsung 850 EVO 500 GB | 2x Seagate Barracuda 2TB | MSI GTX 970 Twin Frozr V | Fractal Design R4 | EVGA 650W

A gaming PC for your budget: $800 - $1000 - $1500 - $1800 - $2600 - $9001

Remember to quote people if you want them to see your reply!

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, HPWebcamAble said:

What's wrong exactly?

 

Just guessing, I'd say this:


result = ((n(7*n-3))/5);

Needs another multiplication symbol, like this:


result = ((n*(7*n-3))/5);

It gives me a compilation error. I just noticed the thing you were pointing out. I changed it but now I get no output.

 

| i7 4790k | H100i | 16GB (8x2) Corsair Vengence | EVGA GTX 780 SC | ASUS Z97 Sabertooth Mark I | Samsung 840 120GB | WD 2TB Green x2 | Rosewill Hive 750W | 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, IvanSnipedYu said:

It gives me a compilation error. I just noticed the thing you were pointing out. I changed it but now I get no output.

You mean mean it doesn't tell you the result?

You need to ask it to print to the console.

 

Here's the method to do that:

system.out.println( "<something to print>" )

 

i7 4790k | MSI Z97S SLI Krait Edition | G.Skill Ripjaws X 16 GB | Samsung 850 EVO 500 GB | 2x Seagate Barracuda 2TB | MSI GTX 970 Twin Frozr V | Fractal Design R4 | EVGA 650W

A gaming PC for your budget: $800 - $1000 - $1500 - $1800 - $2600 - $9001

Remember to quote people if you want them to see your reply!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×