Go Back   Desi Club Torrent » Site Assistance » Help Desk

Help Desk If you need help with something....post all your questions here.






Reply
 
Thread Tools
  #1  
Old 03-24-2008, 07:25 PM
Noobie
 
Join Date: Dec 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
fahad12 is on a distinguished road
Default java help urgent [Answered]

import java.util.Scanner;
import java.text.DecimalFormat;
public class Eggs
{
public static void main(String[] args)
{
int count,formula,lowerLimit,upperLimit,answer=1;
Scanner input = new Scanner(System.in);
System.out.print("FACTORIAL\n");
System.out.print("Lower Limit =");
lowerLimit=input.nextInt();
System.out.print("Upper Limit =");
upperLimit=input.nextInt();

for(count = lowerLimit; count <=upperLimit; count++)
{
answer*=count;

System.out.println(count +" factorial = " + answer);
}

}
}

My incorect output
FACTORIAL
Lower Limit =5
Upper Limit =8
5 factorial = 5
6 factorial = 30
7 factorial = 210
8 factorial = 1680
Sample run:

correct output
FACTORIALS
Lower Limit = 5
Upper Limit = 10
5 factorial = 120
6 factorial = 720
7 factorial = 5040
8 factorial = 40320
9 factorial = 362880
10 factorial = 3628800

please help
  #2  
Old 03-24-2008, 09:47 PM
!~RdA~!'s Avatar
Rab Rakha - Singh is King
 
Join Date: Feb 2006
Location: Chandigarh / Punjab,
Posts: 1,905
Thanks: 887
Thanked 154 Times in 24 Posts
!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute
Default Re: java help urgent

cauz you don't know what factorial is ... first revise factorial section in your maths book..

factorial 5 = 5! = 5*4*3*2*1 = 120

your formula is wrong...

you don't need lower limit in formula for it... the lower limit mentioned above is you need to call ur factorial function with those parameters...

here is an example.. i used ur code and deleted redundant info...

Other suggestion :
code without proper indentation makes life hard.. so enable auto indent of your editor if it is not.. or use notepad++ (windows) or eclipse or emacs (unix/windows)
Code:
public class factorial
{
    public static void main(String[] args)
    {
        int count,lowerLimit,upperLimit,answer=1;

        lowerLimit=1; //don't need
        upperLimit= 10;

        for(count = lowerLimit; count <=upperLimit; count++)
        {
            answer*=count;
        }

        System.out.println(" factorial = " + answer);

    }
}
Answer I got it :-
factorial = 3628800


  #3  
Old 03-24-2008, 09:51 PM
DarkNemesis's Avatar
Kinder Garden Member
 
Join Date: Sep 2007
Location: Look Behind you!
Posts: 104
Thanks: 12
Thanked 3 Times in 1 Post
DarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond repute
Default Re: java help urgent

Do an IRC Search for Java app Programming.
Join Channel and ask what ever you want....Lots of People on Line to help out and shoot the &*^%
LOL

Also....I am not a Java Programmer, but the code looks like recurrsion?
Great if it was Pascal or Modula II or even C.

But never heard of Java having support for Recurrsion....I could be VERY Wrong here.

Best of Luck
DN
  #4  
Old 03-25-2008, 01:56 PM
DarkNemesis's Avatar
Kinder Garden Member
 
Join Date: Sep 2007
Location: Look Behind you!
Posts: 104
Thanks: 12
Thanked 3 Times in 1 Post
DarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond reputeDarkNemesis has a reputation beyond repute
Default Re: java help urgent [Answered]

Good catch RDA......
It's Been a While since I have ben out of School.....close to 20 years.....LOL
  #5  
Old 03-25-2008, 03:23 PM
!~RdA~!'s Avatar
Rab Rakha - Singh is King
 
Join Date: Feb 2006
Location: Chandigarh / Punjab,
Posts: 1,905
Thanks: 887
Thanked 154 Times in 24 Posts
!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute!~RdA~! has a reputation beyond repute
Default Re: java help urgent [Answered]

I can understand...

for me , luckily I was working on some java project and my eclipse was open..

one sight at the formula and i knew that it was wrong.. so just pasted that code and deleted redundent stuff... took 1-2 mins for every thing....

DN, Good job trying to help other
Reply

Bookmarks

Thread Tools





All times are GMT. The time now is 06:01 AM.

Powered by vBulletin 3.7


SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.