4 Replies - 431 Views - Last Post: 27 August 2011 - 11:05 AM Rate Topic: -----

#1 coco24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 08-November 10

New To Java Please Help!

Posted 27 August 2011 - 09:21 AM

Hi, Im new to java and I can not figure out where I am going wrong in this code. I need to take the value from the arguments in the run configuration. I the values are in args[] array and if there is more than one argument I need to print error, but I just am stuck on that part of the code. Here is what I have so far:

public class Numbers {
	static int f(int n) {
		int product = 1;
		while (n > 0) {
			product *= n;
			n -= 1;
		}
		return product;
	}

	public static void main(String[] args) {
		for (int i = 1; i <= 10; i++)
			System.out.println(f(i));
}		
}


Thank you for your time

Is This A Good Question/Topic? 0
  • +

Replies To: New To Java Please Help!

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10390
  • View blog
  • Posts: 38,451
  • Joined: 27-December 08

Re: New To Java Please Help!

Posted 27 August 2011 - 09:24 AM

Happy coding. :)
if(args.length > 1){
    //code
}
else{
    f(Integer.parseInt(args[0]));
}


Was This Post Helpful? 1
  • +
  • -

#3 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: New To Java Please Help!

Posted 27 August 2011 - 09:25 AM

Are you getting error messages? If so, post them EXACTLY, cut and paste.

Is your program not performing as desired? If so, explain what you'd like it to do, what it is doing, and what you think is the source of the problem with as much detail as possible.
Was This Post Helpful? 0
  • +
  • -

#4 coco24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 08-November 10

Re: New To Java Please Help!

Posted 27 August 2011 - 09:52 AM

I got it to work! Thank you!
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10390
  • View blog
  • Posts: 38,451
  • Joined: 27-December 08

Re: New To Java Please Help!

Posted 27 August 2011 - 11:05 AM

Glad I could help! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1