Basic Java Examples

Java Factorial Example

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.

Add Comment

    • 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

  • /*
    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;

  • 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

  • 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.


Facebook Fans