Posts

Showing posts from November, 2022

Program to find the factorial using recursion [Java]

public class Factorial {     static int findFactorial(int n){               if (n == 1)                 return 1;               else                 return(n * findFactorial(n-1));  //calling same method       }        public static void main(String[] args) {   System.out.println("Factorial of 5 is: " + findFactorial(5));   }   } Output: Factorial of 5 is: 120

Simple calculator (Console application/Java)

import java.util.*;  public class calc {     public static void main(String[] args)     {         Scanner sc = new Scanner(System.in);         Double v1, v2 = 0.0;         char decn = 'N';         do {         System.out.println("Which operation do you want to perform (Please select a number)\n"         + "1. Additin\n"         + "2. Subtraction\n"         + "3. Multiplication\n"         + "4. Division\n"         + "5. Modules\n"         + "6. Power");         int ops = sc.nextInt();         switch (ops){         case 1:         System.out.println("Please enter the first nubmer: ");         v1 = sc.nextDouble();   ...