Skip to content

Instantly share code, notes, and snippets.

View BT-ICD's full-sized avatar

Bhavin BT-ICD

  • ICD
  • Gujarat, India
View GitHub Profile
@BT-ICD
BT-ICD / CompoundInterestAnnually.java
Created July 2, 2021 15:49
Example to find compound interest
/**
* Example: To find compound interest annually
* Learning Reference: https://www.easycalculation.com/compound-interest.php
* */
import java.util.Scanner;
public class CompoundInterestAnnually {
public static void main(String[] args) {
double p, r, amount;
int n;
@BT-ICD
BT-ICD / APTest2017Demo_APArrayDemo1.java
Created June 8, 2021 14:07
Example: 2D Successor Array
package APTest2017Demo;
public class APArrayDemo1 {
public static void main(String[] args) {
int[][] arr = {{15,5,9,10},{12,16,11,6},{14,8,13,7}};
int num =80;
Position findPos = Successors.findPosition(num,arr);
if(findPos!=null){
System.out.println("Found at position : " + findPos);
}
@BT-ICD
BT-ICD / HCFDEmo.java
Created June 2, 2021 17:01
Example to find HCF and LCM
/**
* Example: To find HCF - Highest Common Factor (also called Greatest Common Divisor)
* 60 and 40 is 20, i.e, HCF(60,40) = 20
* 100 and 150 is 50, i.e, HCF(150,50) = 50
* 144 and 24 is 24, i.e, HCF(144,24) = 24
* 17 and 89 is 1, i.e, HCF(17,89) = 1
* LCM of (72,120) = 360
* LCM of (15,20) = 60
* Learning Reference:
* https://byjus.com/maths/lcm-of-two-numbers/
@BT-ICD
BT-ICD / JdbcDemo1.java
Created June 1, 2021 12:21
Example: To access data from MySQL database.
/**
* Example: To access data from MySQL database.
* References:
* https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-usagenotes-statements.html
* */
import java.sql.*;
public class JdbcDemo1 {
public static void main(String[] args) {
@BT-ICD
BT-ICD / FibonacciNumbersDemo.java
Created May 19, 2021 14:12
Example: Fibonacci Sequence
/**
* Example: Fibonacci Sequence
* In mathematics, the Fibonacci numbers, commonly denoted Fn, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1.
* Reference: https://en.wikipedia.org/wiki/Fibonacci_number
* Sample Series: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
* */
public class FibonacciNumbersDemo {
public static void main(String[] args) {
int f0, f1, fn;
int num = 20;
@BT-ICD
BT-ICD / GenericDemo_GenericDemoArrayIssue.java
Created May 8, 2021 07:26
Generic Stack - Learn about generic with Array
package GenericDemo;
public class GenericDemoArrayIssue {
public static void main(String[] args) {
ColoredPoint[] cptArray = new ColoredPoint[1];
// cptArray[0]= new Point(); //This is illegal because Point instances have fewer members (only x and y) than ColoredPoint instances (x, y and color). Attempting to access a Point instance's nonexistent color field from its entry in the ColoredPoint array would result in a memory violation (because not memory has been assigned to color) and ultimately crash the JVM.
Point[] ptArray = cptArray; //This is legal because of covariance (an array of supertype references is a supertype of an array of subtype references). In this case, an array of point references is a supertype of an array of ColoredPoint references. Covariance is dangerous when abused. For Example line (ptArray[0] = new Point();) results in ArrayStoredException at runtime because a Point instance is not a ColoredPoint instance. Without this exception, an attempt to access the
@BT-ICD
BT-ICD / GenericMethodUpperBoundDemo1.java
Created May 7, 2021 11:48
Example: Generic Method with upper bound
/**
* Example: Generic Method with upper bound
* The type parameter section specifies that T extends Comparable< T >only objects of classes that implement interface Comparable< T > can be used with this method.
* In this case, Comparable is known as the upper bound of the type parameter.
* By default, Object is the upper bound.
* */
package GenericDemo;
public class GenericMethodUpperBoundDemo1 {
public static void main(String[] args) {
@BT-ICD
BT-ICD / ArraysByRefDemo.java
Created May 5, 2021 14:10
Example: Array variables contain references to arrays.
/**
* Example: Array variables contain references to arrays. When you make an assignment to an array variable, it simply copies the reference. But it doesn’t copy the array itself.
* To create a new copy of array java.util.Arrays provides a method named copyOf.
* Reference:
* https://books.trinket.io/thinkjava2/chapter7.html
*
* */
import java.util.Arrays;
public class ArraysByRefDemo {
@BT-ICD
BT-ICD / BinaryToDecimalDemo.java
Created May 5, 2021 13:21
Example: Conversion from binary to decimal
/**
* Example: Conversion from binary to decimal
* Reference: https://www.rapidtables.com/convert/number/binary-to-decimal.html, https://byjus.com/maths/binary-to-decimal-conversion/
* Sample Data:
* 11 - 3
* 111 - 7
* 101 - 5
* 1111 - 15
* 1001 - 9
*
@BT-ICD
BT-ICD / DecimalToOctalDemo.java
Created April 29, 2021 01:18
Example: Decimal To Octal Conversion
/**
* Example: Conversion from decimal to octal
* Reference: https://www.rapidtables.com/convert/number/decimal-to-binary.html, https://byjus.com/maths/convert-decimal-to-octal/
* Sample Data:
* 11 - 13
* 21 - 25
* 57 - 71
* 17 - 21
*
* Example 1: Convert (127)10 to Octal.