RISHABH LALA
  • Home
  • BLOG
  • About Me
  • INTERESTS
    • AI/Machine Learning >
      • Machine Learning
      • Machine Learning_Complete
      • ML|Text2Speech
    • Statistics 4 Business >
      • Survival | Multilevel | GLM
      • Statistics| Max Likelyhood and OLS
      • Probability Distribution Functions
      • Log and Exponential Transformation
      • Heteroskendasticity and Robust Methods
      • Statistics| Basics II
      • Statistics| Basics I
    • Cloud Architecture >
      • AWS Intro >
        • AWS | Hands On 1
      • Cloud Computing
      • Cloud Architecting
      • BIG DATA >
        • MapReduce
        • SPARK
    • Web Development >
      • WEB APP DEV
      • Java Script
      • Java
      • Network Security
    • BIG DATA FOR BUSINESS >
      • SQL
    • Business Analytics >
      • Lift Curves
      • Market Basket Analysis
    • Valuation | Risk Free Rate >
      • Valuation | Example DCW_Part I
      • Valuation | Example DCW_Part II
      • Valuation | The Idea
      • Valuation | Financial Statements
      • Valuation | DCF & Risk Free Rate
      • Valuation|Equity Risk Premium
      • Valuation | Relative Valuation
      • Valuation | Terminal Value
      • Investing
    • Visualizations
    • Skill Set
    • Academics
  • My Apps
  • Articles
    • Engineering Success
    • Why Hire Me
    • My Poems

JAVA: (Feel free to test me on concepts shown below even during my sleep)

1. Reverse a String
This program takes a string input from the user and reverses it:


import java.util.Scanner;

public class Factorial {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter a number: ");
        int num = scanner.nextInt();
        System.out.println("Factorial of " + num + " = " + factorial(num));
    }

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


2. Factorial of a Number
This program calculates the factorial of a given number using recursion.


import java.util.Scanner;

public class Factorial {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter a number: ");
        int num = scanner.nextInt();
        System.out.println("Factorial of " + num + " = " + factorial(num));
    }

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




3. Fibonacci Sequence
This program generates the Fibonacci sequence up to a specified number of terms.


import java.util.Scanner;

public class Fibonacci {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter the number of terms: ");
        int terms = scanner.nextInt();
        int a = 0, b = 1;
        System.out.print("Fibonacci Series: ");
        for (int i = 0; i < terms; i++) {
            System.out.print(a + " ");
            int nextTerm = a + b;
            a = b;
            b = nextTerm;
        }
    }
}



4. Palindrome Check
This program checks whether a given string is a palindrome.


import java.util.Scanner;

public class PalindromeCheck {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter a string: ");
        String str = scanner.nextLine();
        String reversed = new StringBuilder(str).reverse().toString();
        if (str.equals(reversed)) {
            System.out.println(str + " is a palindrome");
        } else {
            System.out.println(str + " is not a palindrome");
        }
    }
}




5. Prime Number Check
​This program checks whether a given number is prime.


import java.util.Scanner;

public class PrimeCheck {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter a number: ");
        int num = scanner.nextInt();
        if (isPrime(num)) {
            System.out.println(num + " is a prime number");
        } else {
            System.out.println(num + " is not a prime number");
        }
    }

    static boolean isPrime(int n) {
        if (n <= 1) return false;
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (n % i == 0) return false;
        }
        return true;
    }
}

​
Create a free web site with Weebly
  • Home
  • BLOG
  • About Me
  • INTERESTS
    • AI/Machine Learning >
      • Machine Learning
      • Machine Learning_Complete
      • ML|Text2Speech
    • Statistics 4 Business >
      • Survival | Multilevel | GLM
      • Statistics| Max Likelyhood and OLS
      • Probability Distribution Functions
      • Log and Exponential Transformation
      • Heteroskendasticity and Robust Methods
      • Statistics| Basics II
      • Statistics| Basics I
    • Cloud Architecture >
      • AWS Intro >
        • AWS | Hands On 1
      • Cloud Computing
      • Cloud Architecting
      • BIG DATA >
        • MapReduce
        • SPARK
    • Web Development >
      • WEB APP DEV
      • Java Script
      • Java
      • Network Security
    • BIG DATA FOR BUSINESS >
      • SQL
    • Business Analytics >
      • Lift Curves
      • Market Basket Analysis
    • Valuation | Risk Free Rate >
      • Valuation | Example DCW_Part I
      • Valuation | Example DCW_Part II
      • Valuation | The Idea
      • Valuation | Financial Statements
      • Valuation | DCF & Risk Free Rate
      • Valuation|Equity Risk Premium
      • Valuation | Relative Valuation
      • Valuation | Terminal Value
      • Investing
    • Visualizations
    • Skill Set
    • Academics
  • My Apps
  • Articles
    • Engineering Success
    • Why Hire Me
    • My Poems