1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/* Java Factorial Example This Java Factorial Example shows how to calculate factorial of a given number using Java. */ public class NumberFactorial { public static void main(String[] args) { int number = 5; /* * Factorial of any number is !n. * For example, factorial of 4 is 4*3*2*1. */ int factorial = number; for(int i =(number - 1); i > 1; i--) { factorial = factorial * i; } System.out.println("Factorial of a number is " + factorial); } } /* Output of the Factorial program would be Factorial of a number is 120 */ |
it’s nice but i dont understand your code maybe you should elaborate it more
Try this one…
public class NumberFactorial {
public static void main(String args[]){
int number = 5;
int factorial = number;
for(int i=(number – 1); i > 1; i–)
factorial = factorial*i;
System.out.println(“Factorial of the number is” +factorial);
}
}
the o/p will be 120
Yes, you are correct.
the program given for factorail is not working
i want a program for factorial but using constructor
search in google
Quick question. What is a constructor and what do you want it to do?
/*
Please note that two byte array references pointing to null are
considered as equal.
*/
That is incorrect. If you explore the Arrays.equal(…) method, you see that if any of the arrays is null (even both), the result is “not equal” (false).
public static boolean equals(byte[] a, byte[] a2) {
if (a==a2)
return true;
if (a==null || a2==null)
return false;
…
You should add comments beside each line of code to explain what each line does.
the output is not coming 120
The output is 120. Re-read the code. They are doing it for the factorial of 5 and not 4. Ex: (5*4*3*2*1=120)
this is an example which can be undertood easier
public class NumberFactorial{
public static void main(String args[]){
int i,n=5;
int factorial=n;
for(i=1;i<n;i++) factorial=”factorial*i;” system.out.println(“factorial=”+factorial);
}
}”>
Do u think u can give me code to transform this into an applet!!!
And yes if ur asking I am the real pewdiepie
Trying to do stuff in my life rather than playing videogames all day:/LOL
BRO-FIST
Hi everyone! Can you please help me with this problem? I need it very soon. please please please ?
Negotiating a consumer loan is not always straightforward. One form of loan is the discount installment loan, which works as follows. Suppose a loan has a face value of 1000 pesos, the interest rate is 15 percent, and the duration is 18 months. The interest is computed by multiplying the face value of 1000 pesos by 0.15 to yield 150 pesos. The figure is then multiplied by the loan period for 1.5 years to yield 225 pesos as the total interest owed. The amount is immediately deducted from the face value, leaving the consumer with only 775 pesos. Repayment is made in equal monthly installments based on the face value. Thus, the monthly loan payment will be 1000 pesos divided by 18, of 55.56 pesos. This method of calculation may not be too bad of the consumer needs 775 pesos, but the calculation is a bit more complicated if the consumer needs 1000 pesos. Write a program that will take three inputs: the amount the consumer needs to receive, the interest rate, and the duration of the loan in months. The program should then calculate the face value required in order for the consumer to receive the amount needed and should also calculate the monthly payment.