Thursday, September 12, 2019

Calculate factorial of a number using Recursion


Calculate factorial of a number using Recursion




import java.util.Scanner;

public class FactorialOfNumber {

      static int factorial(int n) {
            if (n == 0)
                  return 1;
            else
                  return (n * factorial(n - 1));
      }

      public static void main(String args[]) {
            int i, fact = 1;
            //Input the number
            System.out.println("Enter a Number");
            Scanner sc= new Scanner(System.in);
            int number = sc.nextInt();
           
            fact = factorial(number);
            System.out.println("Factorial of " + number + " is: " + fact);
      }
}



Output:

Enter a Number

5
Factorial of 5 is: 120

Wednesday, September 11, 2019

Print * Patterns in Java

Print * Patterns in Java


* * * * *
 * * * *
  * * *
   * *
    * 

   


Java Code:


public class PatternEx3 {

      public static void main(String[] args) {
            int row = 5;
            for (int i = 0; i <= 5; i++) {
                  // Printing i spaces at the beginning of each row

                  for (int j = 1; j <= i; j++) {
                        System.out.print(" ");
                  }

                  // Printing j *'s at the end of each row

                  for (int j = row; j > 0; j--) {
                        System.out.print("* ");
                  }

                  System.out.println();

                  // Decrementing the row

                  row--;
            }

      }

}

Write a program to calculate grade of Students


Write a program to calculate the grade of Students


Conditions:


A+ >= 85%,
A >= 70% to < 85%
B >= 60% to < 70 %
C >= 50% to < 60%
D >= 40% to < 50%
F < 40%

Instruction:

1. Input the marks from Command Line between 0 and 100.
2. The output will be grade of the student.

i.e :

Case1:

 Please enter the Marks:
 50
 Result: Passed, Grade - C


Case2:

 Please enter the Marks:
 39
 Result: Failed, Grade - F

Tuesday, September 10, 2019

Print triangle star pattern in Java

Print triangle start pattern in Java


    * 
   * * 
  * * * 
 * * * * 
* * * * * 


Java Code:



public class PatternEx2 {

     public static void main(String[] args) {

          int i, j, k;
          //outer loop for row
          for (i = 1; i <= 5; i++) {
              //inner loop: print space
              for (j = 4; j >= i; j--) {
                   System.out.print(" ");
              }
             
              //inner loop: print * with space
              for (k = 1; k <= i; k++) {
                   System.out.print("* ");
              }
              //Print next line
              System.out.println("");
          }

     }
}


Friday, August 30, 2019

CDAC certification courses list

CDAC Certifications Courses List 

IT Applications

Create a Digital Clock using HTML and JavaScript

Create a Digital Clock using HTML and JavaScript  <! DOCTYPE html> < html > < head > ...

Followers

Search This Blog

Popular Posts